Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pic24_all.h"
- #if __PIC24HJ128GP502__
- #define LED1 _RB15 // MicroStick II definitions
- #define LED2 _RB14
- #define LED3 _RB13
- #define SW1 _RB12
- #define SW2 _RB11
- #define CONFIG_LED1() CONFIG_RB15_AS_DIG_OUTPUT()
- #define CONFIG_LED2() CONFIG_RB14_AS_DIG_OUTPUT()
- #define CONFIG_LED3() CONFIG_RB13_AS_DIG_OUTPUT()
- inline void CONFIG_SW1()
- {
- CONFIG_RB12_AS_DIG_INPUT();
- ENABLE_RB12_PULLUP();
- }
- inline void CONFIG_SW2()
- {
- CONFIG_RB11_AS_DIG_INPUT();
- ENABLE_RB11_PILLUP();
- }
- #endif
- int task5(int x)
- {
- return ((x >> 1) ^ x);
- }
- int main(void)
- {
- CONFIG_LED1();
- CONFIG_LED2();
- CONFIG_LED3();
- CONFIG_SW1();
- CONFIG_SW2();
- LED1=0;
- LED2=0;
- LED3=0;
- while (1)
- {
- if(SW1 == 0 && SW2 == 0)
- {
- LED1 = 1;
- LED2 = 1;
- LED3 = 1;
- }
- if(SW1 == 0 && SW2 == 1)
- {
- int i = 0x000;
- LED1 = i % 10;
- LED2 = (i % 100)/10;
- LED3 = (1 % 1000)/100;
- while(SW1 == 1 && SW2 == 1)
- {
- i += 1;
- LED1 = ((i | 0x01) % 10);
- LED2 = ((i | 0x02) % 100)/10;
- LED3 = ((i | 0x04) % 1000)/100;
- DELAY_MS(500);
- if(i == 8)
- i = 0;
- }
- }
- if(SW1 == 1 && SW2 == 0)
- {
- int i = 0x000;
- LED1 = i % 10;
- LED2 = (i % 100)/10;
- LED3 = (1 % 1000)/100;
- while(SW1 == 1 && SW2 == 1)
- {
- i += 1;
- int temp = task5(i);
- LED1 = ((temp | 0x01) % 10);
- LED2 = ((temp | 0x02) % 100)/10;
- LED3 = ((temp | 0x04) % 1000)/100;
- DELAY_MS(500);
- if(i == 8)
- i = 0;
- }
- }
- if(SW1 == 1 && SW2 == 1)
- {
- while(SW1 == 1 && SW2 == 1)
- {
- LED1 = !LED1;
- LED2 = !LED2;
- LED3 = !LED3;
- DELAY_MS(10);
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement