Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. // PIC18F452 Configuration Bit Settings
  2.  
  3. // 'C' source line config statements
  4.  
  5. // CONFIG1H
  6. #pragma config OSC = XT // Oscillator Selection bits (XT oscillator)
  7. #pragma config OSCS = OFF // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is disabled (main oscillator is source))
  8.  
  9. // CONFIG2L
  10. #pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
  11. #pragma config BOR = ON // Brown-out Reset Enable bit (Brown-out Reset enabled)
  12. #pragma config BORV = 20 // Brown-out Reset Voltage bits (VBOR set to 2.0V)
  13.  
  14. // CONFIG2H
  15. #pragma config WDT = OFF // Watchdog Timer Enable bit (WDT enabled)
  16. #pragma config WDTPS = 128 // Watchdog Timer Postscale Select bits (1:128)
  17.  
  18. // CONFIG3H
  19. #pragma config CCP2MUX = ON // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)
  20.  
  21. // CONFIG4L
  22. #pragma config STVR = ON // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET)
  23. #pragma config LVP = ON // Low Voltage ICSP Enable bit (Low Voltage ICSP enabled)
  24.  
  25. // CONFIG5L
  26. #pragma config CP0 = OFF // Code Protection bit (Block 0 (000200-001FFFh) not code protected)
  27. #pragma config CP1 = OFF // Code Protection bit (Block 1 (002000-003FFFh) not code protected)
  28. #pragma config CP2 = OFF // Code Protection bit (Block 2 (004000-005FFFh) not code protected)
  29. #pragma config CP3 = OFF // Code Protection bit (Block 3 (006000-007FFFh) not code protected)
  30.  
  31. // CONFIG5H
  32. #pragma config CPB = OFF // Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
  33. #pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code protected)
  34.  
  35. // CONFIG6L
  36. #pragma config WRT0 = OFF // Write Protection bit (Block 0 (000200-001FFFh) not write protected)
  37. #pragma config WRT1 = OFF // Write Protection bit (Block 1 (002000-003FFFh) not write protected)
  38. #pragma config WRT2 = OFF // Write Protection bit (Block 2 (004000-005FFFh) not write protected)
  39. #pragma config WRT3 = OFF // Write Protection bit (Block 3 (006000-007FFFh) not write protected)
  40.  
  41. // CONFIG6H
  42. #pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
  43. #pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
  44. #pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write protected)
  45.  
  46. // CONFIG7L
  47. #pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
  48. #pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
  49. #pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
  50. #pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)
  51.  
  52. // CONFIG7H
  53. #pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)
  54.  
  55. // #pragma config statements should precede project file includes.
  56. // Use project enums instead of #define for ON and OFF.
  57.  
  58. #include <xc.h>
  59. #define _XTAL_FREQ 4000000
  60. int led1 = 0x01;
  61. int led2 = 0b10000000;
  62. int x =0;
  63. int y =0;
  64. void __interrupt() TIMER0(void)
  65. {
  66. if (PIR1bits.TMR2IF)
  67. {
  68.  
  69. PIR1bits.TMR2IF=0;
  70.  
  71. if (x<7)
  72. {
  73. led1 = led1<<1;
  74. x++;
  75. }
  76. else if (x>=7 && x<14)
  77. {
  78. led1 = led1>>1;
  79. x++;
  80. }
  81. else
  82. {
  83. x=0;
  84. }
  85.  
  86. }
  87. else
  88. {
  89. PIR2bits.TMR3IF=0;
  90.  
  91. if (y<7)
  92. {
  93. led2 = led2>>1;
  94. y++;
  95. }
  96. else if (y>=7 && y<14)
  97. {
  98. led2 = led2<<1;
  99. y++;
  100. }
  101. else
  102. {
  103. y=0;
  104. }
  105. TMR3H=0xC0;
  106. TMR3L=0x86;
  107.  
  108. }
  109. PORTD = led1|led2;
  110.  
  111. }
  112.  
  113. void main(void)
  114. {
  115. TRISD=0;
  116. INTCONbits.GIE=1; //global interrupt enable
  117. INTCONbits.PEIE=1;
  118. PIE1bits.TMR2IE=1;
  119. PIR1bits.TMR2IF=0;
  120. PIE2bits.TMR3IE=1;
  121. PIR2bits.TMR3IF=0;
  122.  
  123.  
  124. T2CONbits.T2CKPS=3;
  125. T2CONbits.TOUTPS=15;
  126. PR2 = 250;
  127.  
  128. T3CONbits.T3CKPS= 2;
  129. TMR3H=0xC0;
  130. TMR3L=0x86;
  131.  
  132.  
  133.  
  134. T2CONbits.TMR2ON=1;
  135. T3CONbits.TMR3ON=1;
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145. while(1);
  146.  
  147. return;
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement