Advertisement
abdullahkahraman

main.c

Jun 21st, 2013
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.89 KB | None | 0 0
  1. #include <hidef.h> /* for EnableInterrupts macro */
  2. #include "derivative.h" /* include peripheral declarations */
  3. #include "init.h" // Include the header file that includes I/O definitions
  4. volatile unsigned int counter = 0;
  5. unsigned char dummy = 0;
  6.  
  7. typedef union
  8. {
  9.     unsigned char LEDs;
  10.     struct
  11.     {
  12.         unsigned char bit0 :1;
  13.         unsigned char bit1 :1;
  14.         unsigned char bit2 :1;
  15.         unsigned char bit3 :1;
  16.         unsigned char bit4 :1;
  17.         unsigned char bit5 :1;
  18.         unsigned char bit6 :1;
  19.         unsigned char bit7 :1;
  20.     } bits;
  21. } _LED_register;
  22.  
  23. _LED_register LED_register;
  24.  
  25. interrupt VectorNumber_Vmtim0 void MTIM0_ISR(void)
  26. {
  27.     // Dummily read MTIMx_SC register and
  28.     // then write a 0 to MTIMxSC[TOF]
  29.     MTIM0_overflow = MTIM0_stop;
  30.     LED1 = ~LED1;
  31. }
  32.  
  33.  
  34. interrupt VectorNumber_Virq_wdog void WDOG_ISR(void)
  35. {
  36.     touch_LED = 0;
  37. }
  38.  
  39. void updateLEDs(void)
  40. {
  41.     LED1 = ~LED_register.bits.bit0;
  42.     LED2 = ~LED_register.bits.bit1;
  43.     LED3 = ~LED_register.bits.bit2;
  44.     LED4 = ~LED_register.bits.bit3;
  45.     LED5 = ~LED_register.bits.bit4;
  46.     LED6 = ~LED_register.bits.bit5;
  47.     LED7 = ~LED_register.bits.bit6;
  48.     LED8 = ~LED_register.bits.bit7;
  49. }
  50.  
  51. void main(void)
  52. {
  53.     EnableInterrupts;
  54.  
  55.     initialize_CPU();
  56.     initialize_IO();
  57.    
  58.     LED_ctrl = 1;
  59.     LED5 = 0;
  60.  
  61.     counter = 0xFFFF;
  62.     while (counter > 0)
  63.     {
  64.         counter--;
  65.         __RESET_WATCHDOG();
  66.     }
  67.  
  68.     LED_ctrl = 0;
  69.     LED5 = 1;
  70.  
  71.     counter = 0xFFFF;
  72.     while (counter > 0)
  73.     {
  74.         counter--;
  75.         __RESET_WATCHDOG();
  76.     }
  77.  
  78.     LED_ctrl = 1;
  79.     LED_register.LEDs = SYS_SRS;
  80.     updateLEDs();
  81.  
  82.     dummy = 0x05;
  83.     while (dummy > 0)
  84.     {
  85.         counter = 0xFFFF;
  86.         while (counter > 0)
  87.         {
  88.             counter--;
  89.             __RESET_WATCHDOG();
  90.         }
  91.         dummy--;
  92.     }
  93.  
  94.     LED_ctrl = 0;
  95.     LED_register.LEDs = 0;
  96.  
  97.     // initialize_MTIM0();
  98.  
  99.     for (;;)
  100.     {
  101.         LED7 = ~LED7;
  102.         LED8 = ~LED8;
  103.         // __RESET_WATCHDOG(); /* feeds the dog  */
  104.  
  105.         /* loop forever */
  106.         /* please make sure that you never leave main */
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement