void main(void) {
CMCON = 0x07; // switch off comparators;
TRISA = 0xFF; // set portA as inputs
// set portB as outputs
TRISB = 0;
PORTB = 0; //init portb, all leds off at start
while(1) // continually
{
if (PORTA.f0) // if there's a trigger pulse
{
PORTB.f0 = 1; // turn the LED on
Delay_ms(70) ;
PORTB.f0 = 0; // turn led off
}
if (PORTA.f1) // if there's a trigger pulse
{
PORTB.f1 = 1; // turn the LED on
Delay_ms(70) ; // wait 500 ms
PORTB.f1 = 0; // turn led off
}
if (PORTA.f2)
{
PORTB.f2 = 1;
Delay_ms(70) ;
PORTB.f2 = 0;
}
if (PORTA.f3)
{
PORTB.f3 = 1;
Delay_ms(70) ;
PORTB.f3 = 0;
}
}
}
while(1)
{
Temp = PORTA;
if(Temp ^ PORTA) DoSomething();
}
while(1)
{
if (PORTA.f0) // if there's a trigger pulse
{
INTERRUPT
flag0=1
}
if (PORTA.f1)
{
INTERRUPT
flag1=1
}
if (PORTA.f2)
{
INTERRUPT
flag2=1
}
}
interrupt routine()
if (flag0)
turn led0 on;
delay;
turn led0 off;
flag0=0;
else if (flag1)
turn led1 on;
delay;
turn led1 off;
flag1=0;
etc....
while(1) // continually
{
if (PORTA.f0) // if there's a trigger pulse
{
PORTB.f0 = 1; // turn the LED on
offCnt0 =70;
}
if (PORTA.f1) // if there's a trigger pulse
{
PORTB.f1 = 1; // turn the LED on
offCnt1 =70;
}
if (PORTA.f2)
{
PORTB.f2 = 1;
offCnt2 =70;
}
if (PORTA.f3)
{
PORTB.f3 = 1;
offCnt3 =70;
}
}
}
if(offCnt0--)
{
if(offCnt0}
PORTB.f0 = 0;
}
if(offCnt1--)
{
if(offCnt1}
PORTB.f1 = 0;
}
if(offCnt2--)
{
if(offCnt2}
PORTB.f2 = 0;
}
if(offCnt3--)
{
if(offCnt3}
PORTB.f3 = 0;
}
void main(void) {
CMCON = 0x07; // switch off comparators;
TRISA = 0xFF; // set portA as inputs
TRISB = 0; // set portB as outputs
PORTB = 0; //init portb, all leds off at start
TOCS = 0; // external clock
int counter1 = 0;
int counter2 = 0; // counters for the 4 leds
int counter3 = 0;
int counter4 = 0;
int blink_duration = 70;
while (1) {
if (PORTA.f0) // if there's a hit
{ led1; }
if (PORTA.f1) // if there's a hit
{ led2; }
if (PORTA.f2) // if there's a hit
{ led3; }
if (PORTA.f3) // if there's a hit
{ led4; }
}
}
void led1()
{
if(counter1<blink_duration){
counter1++;
PORTB.f0 = 1; // turn the LED on
}
counter1=0;
PORTB.f0 = 0; // turn the LED off
}
// do the same for the other 3 leds...
void led1()
{
while(counter1<blink_duration){
counter1++;
PORTB.f0 = 1; // turn the LED on
}
counter1=0;
PORTB.f0 = 0; // turn the LED off
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?