Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.53 KB | None | 0 0
  1.  
  2. sbit LCD_RS at RA4_bit;
  3. sbit LCD_EN at RA5_bit;
  4. sbit LCD_D4 at RA0_bit;
  5. sbit LCD_D5 at RA1_bit;
  6. sbit LCD_D6 at RA2_bit;
  7. sbit LCD_D7 at RA3_bit;
  8. sbit LCD_RS_Direction at TRISA4_bit;
  9. sbit LCD_EN_Direction at TRISA5_bit;
  10. sbit LCD_D4_Direction at TRISA0_bit;
  11. sbit LCD_D5_Direction at TRISA1_bit;
  12. sbit LCD_D6_Direction at TRISA2_bit;
  13. sbit LCD_D7_Direction at TRISA3_bit;
  14.  
  15.  
  16. const int len = 16;
  17. unsigned int cnt;
  18. char text[20], text2[20];
  19. int pomestuvanje;
  20.  
  21. void interrupt() {
  22.     if (TMR0IF_bit == 1){
  23.         cnt++;
  24.         TMR0 = 64;
  25.         TMR0IF_bit = 0;
  26.     }
  27.    
  28.     if (INTF_bit == 1) {                      // if RBO/INT == 1 ?
  29.        INTF_bit = 0;
  30.     }
  31. }
  32.  
  33. int main() {
  34.     OPTION_REG.PS0 = 1;              // 1:64 prescaler
  35.     OPTION_REG.PS2 = 1;
  36.    
  37.     INTCON.B7 = 1;                        // GIE = 1
  38.     INTCON.B4 = 1;                        // RBO/INT = 1
  39.     INTCON.B5 = 1;                          //T0IE - TMR0 Overflow Interrupt Enable bit = 1
  40.    
  41.     C1ON_bit = 0;
  42.     C2ON_bit = 0;
  43.  
  44.     ANSEL = 0;
  45.     ANSELH = 0;
  46.     Lcd_Init();
  47.     Lcd_Cmd(_LCD_CURSOR_OFF);
  48.     Lcd_Cmd(_LCD_CLEAR);
  49.  
  50.     TRISB.B0 = 1;        // B0 e vlezen bit
  51.     pomestuvanje = 1;    // pocni od prva pozicija levo
  52.     TMR0 = 64;      // od prescaler do 255
  53.     cnt = 0;
  54.  
  55.     /// 255 - 64 + 1 = 192
  56.     /// 22 ms = 22/1000
  57.     /// 2 000 000 / (64 * 192) * 22/1000 = 3.5087 ~ 4
  58.  
  59.  
  60.  
  61.     while (1) {
  62.          if (PORTB.B0) {                        // pecati samo ime
  63.            Lcd_Cmd(_LCD_CURSOR_OFF);
  64.            Lcd_Cmd(_LCD_CLEAR);
  65.              while(PORTB.B0){
  66.                strcpy(text,"Gjorgji");
  67.                Lcd_Out(1,1,text);
  68.              }
  69.          } else {                                // ako e prezime resetiraj tajmer
  70.             cnt = 0;
  71.             TMR0 = 64;
  72.             Lcd_Cmd(_LCD_CURSOR_OFF);
  73.             Lcd_Cmd(_LCD_CLEAR);
  74.             strcpy(text,"Kirkov");
  75.             Lcd_Out(2,pomestuvanje,text);          // ispecati go ednas
  76.  
  77.             do {
  78.                if (pomestuvanje >= 16) {          //
  79.                   pomestuvanje = 1;
  80.                }
  81.                
  82.                if (cnt>=4){    // pominale 22ms pecati za edna nadesno
  83.                 Lcd_Cmd(_LCD_CURSOR_OFF);
  84.                 Lcd_Cmd(_LCD_CLEAR);
  85.                 strcpy(text,"Kirkov");
  86.                 Lcd_Out(2,pomestuvanje,text);
  87.                 cnt = 0;
  88.                 TMR0 = 64;
  89.                 pomestuvanje++;
  90.                }
  91.  
  92.  
  93.             } while (PORTB.B0 == 0);
  94.          }
  95.     }
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement