Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sbit LCD_RS at RA4_bit;
- sbit LCD_EN at RA5_bit;
- sbit LCD_D4 at RA0_bit;
- sbit LCD_D5 at RA1_bit;
- sbit LCD_D6 at RA2_bit;
- sbit LCD_D7 at RA3_bit;
- sbit LCD_RS_Direction at TRISA4_bit;
- sbit LCD_EN_Direction at TRISA5_bit;
- sbit LCD_D4_Direction at TRISA0_bit;
- sbit LCD_D5_Direction at TRISA1_bit;
- sbit LCD_D6_Direction at TRISA2_bit;
- sbit LCD_D7_Direction at TRISA3_bit;
- const int len = 16;
- unsigned int cnt;
- char text[20], text2[20];
- int pomestuvanje;
- void interrupt() {
- if (TMR0IF_bit == 1){
- cnt++;
- TMR0 = 64;
- TMR0IF_bit = 0;
- }
- if (INTF_bit == 1) { // if RBO/INT == 1 ?
- INTF_bit = 0;
- }
- }
- int main() {
- OPTION_REG.PS0 = 1; // 1:64 prescaler
- OPTION_REG.PS2 = 1;
- INTCON.B7 = 1; // GIE = 1
- INTCON.B4 = 1; // RBO/INT = 1
- INTCON.B5 = 1; //T0IE - TMR0 Overflow Interrupt Enable bit = 1
- C1ON_bit = 0;
- C2ON_bit = 0;
- ANSEL = 0;
- ANSELH = 0;
- Lcd_Init();
- Lcd_Cmd(_LCD_CURSOR_OFF);
- Lcd_Cmd(_LCD_CLEAR);
- TRISB.B0 = 1; // B0 e vlezen bit
- pomestuvanje = 1; // pocni od prva pozicija levo
- TMR0 = 64; // od prescaler do 255
- cnt = 0;
- /// 255 - 64 + 1 = 192
- /// 22 ms = 22/1000
- /// 2 000 000 / (64 * 192) * 22/1000 = 3.5087 ~ 4
- while (1) {
- if (PORTB.B0) { // pecati samo ime
- Lcd_Cmd(_LCD_CURSOR_OFF);
- Lcd_Cmd(_LCD_CLEAR);
- while(PORTB.B0){
- strcpy(text,"Gjorgji");
- Lcd_Out(1,1,text);
- }
- } else { // ako e prezime resetiraj tajmer
- cnt = 0;
- TMR0 = 64;
- Lcd_Cmd(_LCD_CURSOR_OFF);
- Lcd_Cmd(_LCD_CLEAR);
- strcpy(text,"Kirkov");
- Lcd_Out(2,pomestuvanje,text); // ispecati go ednas
- do {
- if (pomestuvanje >= 16) { //
- pomestuvanje = 1;
- }
- if (cnt>=4){ // pominale 22ms pecati za edna nadesno
- Lcd_Cmd(_LCD_CURSOR_OFF);
- Lcd_Cmd(_LCD_CLEAR);
- strcpy(text,"Kirkov");
- Lcd_Out(2,pomestuvanje,text);
- cnt = 0;
- TMR0 = 64;
- pomestuvanje++;
- }
- } while (PORTB.B0 == 0);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement