please help why dose the code work with tmr0l but not tmr0h

Discussion in 'The Projects Forum' started by mhghost, May 17, 2013.

  1. mhghost

    Thread Starter New Member

    May 16, 2013
    6
    0
    hi i am trying to make a project and her is a small part of it
    here is the code

    Code ( (Unknown Language)):
    1.  
    2. sbit LCD_RS at RD2_bit;
    3. sbit LCD_EN at RD3_bit;
    4. sbit LCD_D4 at RD4_bit;
    5. sbit LCD_D5 at RD5_bit;
    6. sbit LCD_D6 at RD6_bit;
    7. sbit LCD_D7 at RD7_bit;
    8.  
    9. sbit LCD_RS_Direction at TRISD2_bit;
    10. sbit LCD_EN_Direction at TRISD3_bit;
    11. sbit LCD_D4_Direction at TRISD4_bit;
    12. sbit LCD_D5_Direction at TRISD5_bit;
    13. sbit LCD_D6_Direction at TRISD6_bit;
    14. sbit LCD_D7_Direction at TRISD7_bit;
    15.      char lcd[6];
    16.      unsigned long x ;
    17. void main() {
    18.  
    19.    TRISA=1 ;
    20.    TRISd = 0;
    21.    PORTd= 0 ;
    22.  
    23.    delay_ms(200);
    24.     LCD_Init();
    25.     LCD_Out(1, 1, "Speed In RPM:");
    26.     TMR0H = TMR0L = 0;
    27.  
    28.      T0CON=96;
    29.  
    30.  delay_ms(2000);
    31.  
    32.  
    33.  
    34.   while(1) { x = (TMR0H<<8 ) + TMR0l;
    35.  
    36.       inttostr (x,lcd);
    37.  
    38.       lcd_out(2,1,lcd);
    39.       delay_ms (2000);
    40.  
    41.  
    42.  
    43.    }
    44.  
    45.  }
    46.  
    but when i use tmr0h my nothing happens i am useing a 4 MHz and isis simulator and in anther part of it i get this error

    "Simulation is not running in real time due to excessive CPU load".
     
    Last edited by a moderator: May 17, 2013
  2. mhghost

    Thread Starter New Member

    May 16, 2013
    6
    0
    oh sorry wrong code here is the one with the problem

    Code ( (Unknown Language)):
    1.  
    2. sbit LCD_RS at RB4_bit;
    3. sbit LCD_EN at RB5_bit;
    4. sbit LCD_D4 at RB0_bit;
    5. sbit LCD_D5 at RB1_bit;
    6. sbit LCD_D6 at RB2_bit;
    7. sbit LCD_D7 at RB3_bit;
    8.  
    9. sbit LCD_RS_Direction at TRISB4_bit;
    10. sbit LCD_EN_Direction at TRISB5_bit;
    11. sbit LCD_D4_Direction at TRISB0_bit;
    12. sbit LCD_D5_Direction at TRISB1_bit;
    13. sbit LCD_D6_Direction at TRISB2_bit;
    14. sbit LCD_D7_Direction at TRISB3_bit;
    15.  
    16.   char txt2[10];
    17.   char txt1[10];
    18.   int  x=0;
    19.   int y=0;
    20.   int q =0;
    21.    void main(){
    22.    TRISB =0;
    23.  
    24.     Lcd_Init();
    25.     delay_ms(2000);
    26.     lcd_cmd( _LCD_CURSOR_OFF);
    27.     T0CON =0b10001111;
    28.     lcd_out (1,1,"time is ");
    29.     lcd_out(2,1,"m=0");
    30.     lcd_out(2,9,"s=0");
    31.   while(1){
    32.  
    33.  
    34.  
    35.     //while(tmr0h < 0b00000001){}
    36.    
    37.    
    38.     while(tmr0l < 0b11111111){}
    39.     lcd_out (1,1,"time is ");
    40.     x++;
    41.     T0CON =0b00001111;
    42.  
    43.     tmr0h=0;
    44.     tmr0l=0;
    45.     T0CON =0b10001111;
    46.  
    47.   if(x==38){x=0;q++;}
    48.   if(q==60){q=0;y++;}
    49.  
    50.   inttostr(q,txt1);
    51.   inttostr(y,txt2);
    52.   ltrim(txt1);
    53.   ltrim(txt2);
    54.   lcd_out(2,1,"m=");
    55.   lcd_out_cp(txt2);
    56.   lcd_out(2,9,"s=");
    57.   if(q<10){ lcd_out_cp("0");}
    58.   lcd_out_cp(txt1);
    59.  
    60.  
    61. }   }
    62.  
     
    Last edited by a moderator: May 17, 2013
  3. Dodgydave

    Distinguished Member

    Jun 22, 2012
    4,969
    744
    Which Pic are you using?
     
  4. mhghost

    Thread Starter New Member

    May 16, 2013
    6
    0
    i am using 18f452

    and the code works with a delay of 5 sec per mint i don't know why i tried to change the tmr0l limit but it dose not change any thing and when i try to use timer high the isis frezess
     
  5. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    from page 107 in the datasheet:
    You have to read the low bye in order for the high byte buffer to be loaded with the current value.
     
Loading...