Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. // LCD module connections
  2. sbit LCD_RS at RB0_bit;
  3. sbit LCD_EN at RB1_bit;
  4. sbit LCD_D4 at RB4_bit;
  5. sbit LCD_D5 at RB5_bit;
  6. sbit LCD_D6 at RB6_bit;
  7. sbit LCD_D7 at RB7_bit;
  8. sbit LCD_RS_Direction at TRISB0_bit;
  9. sbit LCD_EN_Direction at TRISB1_bit;
  10. sbit LCD_D4_Direction at TRISB4_bit;
  11. sbit LCD_D5_Direction at TRISB5_bit;
  12. sbit LCD_D6_Direction at TRISB6_bit;
  13. sbit LCD_D7_Direction at TRISB7_bit;
  14. // End LCD module connections
  15.  
  16. char txt1[]="Running";
  17. char txt2[]="Stopped";
  18.  
  19. void runMotor()
  20. {
  21. TRISB = 0;
  22. PORTB = 0;
  23. Lcd_Init(); // Initialize LCD
  24. Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
  25. Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
  26. Lcd_Out(1,1,txt1);
  27.  
  28. CMCON = 0x07; // To turn off comparators
  29. ADCON1 = 0x06; // To turn off analog to digital converters
  30. TRISD = 0; // PORT D as output port
  31. PORTD = 0x0F;
  32. do
  33. {
  34. PORTD = 0b00000011;
  35. Delay_ms(100);
  36. PORTD = 0b00000110;
  37. Delay_ms(100);
  38. PORTD = 0b00001100;
  39. Delay_ms(100);
  40. PORTD = 0b00001001;
  41. Delay_ms(100);
  42. }while(1);
  43. }
  44.  
  45. void stopMotor()
  46. {
  47. TRISB = 0;
  48. PORTB = 0;
  49. Lcd_Init(); // Initialize LCD
  50. Lcd_Cmd(_LCD_CLEAR); // Clear LCD display
  51. Lcd_Cmd(_LCD_CURSOR_OFF); // Turn cursor off
  52. Lcd_Out(1,1,txt2);
  53.  
  54. CMCON = 0x07; // To turn off comparators
  55. ADCON1 = 0x06; // To turn off analog to digital converters
  56. TRISD = 0; // PORT D as output port
  57. PORTD = 0x0F;
  58. do
  59. {
  60. PORTD = 0b00000000;
  61. Delay_ms(100);
  62. PORTD = 0b00000000;
  63. Delay_ms(100);
  64. PORTD = 0b00000000;
  65. Delay_ms(100);
  66. PORTD = 0b00000000;
  67. Delay_ms(100);
  68. }while(1);
  69. }
  70.  
  71. void main()
  72. {
  73. runMotor();
  74.  
  75. TRISC.F0 = 1;
  76. TRISC.F1 = 1;
  77. while(1)
  78. {
  79. if(Button(&PORTC,0,10,0))
  80. {
  81. runMotor();
  82. }
  83. if(Button(&PORTC,1,10,0))
  84. {
  85. stopMotor();
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement