Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pic24_all.h"
- #if __PIC24HJ128GP502__
- #define LED1 _LATA0 // MicroStick II definitions
- #define LED2 _LATA1
- #define LED3 _LATA2
- #define SW1 _LATA3
- #define SW2 _LATA4
- #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)
- {
- int temp = x >> 1;
- return temp;
- }
- 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)
- {
- while(SW1 == 0 && SW2 == 1)
- {
- int i = 0, j = 0, k = 0;
- for(; i < 2; i++)
- {
- for(; j < 2; j++)
- {
- for(; k < 2; k++)
- {
- led3 = !led3;
- DELAY_MS(500);
- }
- led2 = !led2;
- DELAY_MS(500);
- }
- led1 = !led1;
- DELAY_MS(500);
- }
- }
- }
- if(SW1 == 1 && SW2 == 0)
- {
- while(SW1 == 1 && SW2 == 0)
- {
- LED1 = 0;
- LED2 = 0;
- LED3 = 0;
- DELAY_MS(500);
- LED1 = 0;
- LED2 = 0;
- LED3 = 1;
- DELAY_MS(500);
- LED1 = 0;
- LED2 = 1;
- LED3 = 1;
- DELAY_MS(500);
- LED1 = 0;
- LED2 = 1;
- LED3 = 0;
- DELAY_MS(500);
- LED1 = 1;
- LED2 = 1;
- LED3 = 0;
- DELAY_MS(500);
- LED1 = 1;
- LED2 = 1;
- LED3 = 1;
- DELAY_MS(500);
- LED1 = 1;
- LED2 = 0;
- LED3 = 1;
- DELAY_MS(500);
- LED1 = 1;
- LED2 = 0;
- LED3 = 0;
- DELAY_MS(500);
- }
- }
- if(SW1 == 1 && SW2 == 1)
- {
- 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 % 10;
- LED2 = (temp % 100)/10;
- LED3 = (temp % 1000)/100;
- DELAY_MS(500);
- if(i == 8)
- i = 0;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement