I need to Flash the LED four times at a rate of one flash per second.and then turn it OFF ,i manage to get to flash but i do not know how to stop it at 4 .
please help me
thanks
this is what i have done so far :
#include <xc.h>
#define TRUE 1
#define FALSE 0
#define FOSC 20000000L /* target device system clock freqency */
#define FCYC (FOSC/4L) /* target device instruction clock freqency */
#define _XTAL_FREQ FOSC /* required for HITECH PICC delay macros */
// Configuration settings
#pragma config OSC=HS,FSCM=OFF,IESO=OFF
#pragma config PWRT=ON,BOR=OFF,BORV=45
#pragma config WDT=OFF
#pragma config MCLRE=ON
#pragma config STVR=OFF,LVP=OFF,DEBUG=OFF
#pragma config CP0=OFF,CP1=OFF
#pragma config CPB=OFF,CPD=OFF
#pragma config WRT0=OFF,WRT1=OFF
#pragma config WRTB=OFF,WRTC=OFF,WRTD=OFF
#pragma config EBTR0=OFF,EBTR1=OFF
#pragma config EBTRB=OFF
//===============================================================
void main(void)
{
OSCCONbits.SCS0=0; //set oscillator to primary (external)
OSCCONbits.SCS1=0;
TRISA = 0b11111111; //Set port input output directions
TRISB = 0b00000000;
ADCON1 = 0b11111100; //All bits digital I/O except AN0 and AN1
RCON=0b00000000; //disable interrupt priorities (compatible with 16F series)
INTCON=0b00000000; //disable interrupts
INTCON2=0b00000000; //pull-ups enabled interrupt are all low priority
PORTA=0xFF; //Turn off seven segment display
PORTB=0xFF; //Note LED’s active low ie turned on with logic 0
while(1)
{
PORTBbits.RB4=1;//LED ON
__delay_ms(500);
PORTBbits.RB4=0;//LED OFF
__delay_ms(500);
}
}
please help me
thanks
this is what i have done so far :
#include <xc.h>
#define TRUE 1
#define FALSE 0
#define FOSC 20000000L /* target device system clock freqency */
#define FCYC (FOSC/4L) /* target device instruction clock freqency */
#define _XTAL_FREQ FOSC /* required for HITECH PICC delay macros */
// Configuration settings
#pragma config OSC=HS,FSCM=OFF,IESO=OFF
#pragma config PWRT=ON,BOR=OFF,BORV=45
#pragma config WDT=OFF
#pragma config MCLRE=ON
#pragma config STVR=OFF,LVP=OFF,DEBUG=OFF
#pragma config CP0=OFF,CP1=OFF
#pragma config CPB=OFF,CPD=OFF
#pragma config WRT0=OFF,WRT1=OFF
#pragma config WRTB=OFF,WRTC=OFF,WRTD=OFF
#pragma config EBTR0=OFF,EBTR1=OFF
#pragma config EBTRB=OFF
//===============================================================
void main(void)
{
OSCCONbits.SCS0=0; //set oscillator to primary (external)
OSCCONbits.SCS1=0;
TRISA = 0b11111111; //Set port input output directions
TRISB = 0b00000000;
ADCON1 = 0b11111100; //All bits digital I/O except AN0 and AN1
RCON=0b00000000; //disable interrupt priorities (compatible with 16F series)
INTCON=0b00000000; //disable interrupts
INTCON2=0b00000000; //pull-ups enabled interrupt are all low priority
PORTA=0xFF; //Turn off seven segment display
PORTB=0xFF; //Note LED’s active low ie turned on with logic 0
while(1)
{
PORTBbits.RB4=1;//LED ON
__delay_ms(500);
PORTBbits.RB4=0;//LED OFF
__delay_ms(500);
}
}