Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #include <16F886.h>
  2. #device ADC=10 *=16
  3.  
  4. #FUSES NOWDT //No Watch Dog Timer
  5. #FUSES PUT //Power Up Timer
  6. #FUSES NOMCLR //Master Clear pin not enabled
  7. #FUSES NOPROTECT //Code not protected from reading
  8. #FUSES NOCPD //No EE protection
  9. #FUSES BROWNOUT //Brownout reset
  10. #FUSES IESO //Internal External Switch Over mode enabled
  11. #FUSES FCMEN //Fail-safe clock monitor enabled
  12. #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
  13. #FUSES NODEBUG //No Debug mode for ICD
  14. #FUSES NOWRT //Program memory not write protected
  15. #FUSES BORV40 //Brodddddwnout reset at 4.0V
  16. #FUSES RESERVED //Used to set the reserved FUSE bits
  17. #FUSES INTRC_IO
  18.  
  19. #use delay(clock=8M)
  20. #define SLAVE_ADDRESS 0xB0
  21. //#define SLAVE_ADDRESS 0xD0
  22.  
  23. #use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
  24. #use i2c(MASTER, I2C1, FORCE_HW) // configure the i2c port
  25.  
  26.  
  27. int counter=0;
  28. int counter2=0;
  29. int duty=0;
  30. int y=1;
  31. int pwd=1;
  32. int pwd2=1;
  33.  
  34. #INT_TIMER1
  35. void timer1_isr(){
  36. set_timer1(65036);
  37. counter++;
  38. counter2++;
  39.  
  40. if (counter == 19) { counter = 0;}
  41. if (counter == 0) {
  42.  
  43. output_high(PIN_B4);} // beginning of a new period
  44.  
  45. if (counter2 == 19) { counter2 = 0;}
  46. if (counter2 == 0) {
  47.  
  48. output_high(PIN_B4);} // beginning of a new period
  49.  
  50.  
  51. if (counter == pwd) {output_low(PIN_B4);}
  52. if(counter2 == pwd2){output_low(PIN_B3);}
  53. }
  54.  
  55.  
  56.  
  57. void main() {
  58. setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
  59. set_timer1(65036);
  60. enable_interrupts(INT_TIMER1);
  61. enable_interrupts(GLOBAL);
  62.  
  63. //Counter = 0;
  64. // Duty = 3;
  65. While(1){
  66.  
  67. if (!input(PIN_B7) && y==1) {
  68. output_high(PIN_B5);
  69. delay_ms(1000);
  70. if(pwd==1){
  71. pwd=2;
  72.  
  73. output_low(PIN_B5);
  74.  
  75.  
  76. }else{
  77. pwd=1;
  78. //output_high(PIN_B5);
  79. }
  80.  
  81. if(pwd2==2){
  82. pwd2=1;
  83. output_low(PIN_B5);
  84. }else{
  85. pwd2=2;
  86. //output_high(PIN_B5);
  87. }
  88.  
  89.  
  90. y=0;
  91. delay_ms(200);
  92. }else{
  93. y=1;
  94. }
  95.  
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement