Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pic24_all.h"
- void a_delay(void)
- {
- uint16_t i, k;
- for(k = 1800; --k;)
- {
- for(i = 3600; --i;);
- }
- }
- void b_delay(void)
- {
- uint16_t i, k;
- for(k = 900; --k;)
- {
- for(i = 3600; --i;);
- }
- }
- void blinkLed1(unsigned times) {
- unsigned i = 0;
- for(i = 0; i < times; ++i) {
- _LATB2 = 1;
- a_delay();
- _LATB2 = 0;
- a_delay();
- }
- }
- void blinkLed2(unsigned times) {
- unsigned i = 0;
- for(i = 0; i < times; ++i) {
- _LATB5 = 1;
- b_delay();
- _LATB5 = 0;
- b_delay();
- }
- }
- int main(void)
- {
- configClock();
- ODCB = 0;
- _ODCB14 = 1;
- _ODCB12 = 1;
- TRISB = 0;
- _TRISB14 = 1;
- _TRISB12 = 1;
- _LATB2 = 1;
- unsigned state = 1;
- unsigned lastSwitchStateA = 0
- unsigned lastSwitchStateB = 0;
- unsigned currentSwitchStateA = 0;
- unsigned currentSwitchStateB = 0;
- while(1)
- {
- currentSwitchA = _LATB14;
- currentSwitchB = _LATB12;
- if(state == 1) {
- if(!currentSwitchA && lastSwitchA) {
- _LATB2 = 0;
- state = 2;
- }
- } else if(state == 2) {
- if(!currentSwitchA && lastSwitchA) {
- blindLed1(2);
- _LATB2 = 1;
- _LATB5 = 1;
- state = 3;
- }
- } else if(state == 3) {
- if(!currentSwitchA && lastSwitchA) {
- if(currentSwitchB)
- state = 1;
- else
- state = 2;
- }
- } else if(state == 4) {
- if(currentSwitchA) {
- while(1) {
- blinkLed1(1);
- if(!currentSwitchA) {
- state = 5;
- break;
- }
- }
- }
- } else if(state == 5) {
- while(1) {
- blinkLed2(1);
- if(!currentSwitchA && lastSwitchA) {
- state = 6;
- break;
- }
- }
- } else if(state == 6) {
- while(1) {
- blinkLed1(1);
- blinkLed2(1);
- if(!currentSwitchA && lastSwitchA) {
- _LATB2 = 0;
- _LATB5 = 0;
- state = 1;
- }
- }
- }
- lastSwitchStateA = currentSwitchStateA;
- lastSwitchStateB = currentSwitchStateB;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement