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

Thread Starter

mhghost

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

Rich (BB code):
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
     char lcd[6];
     unsigned long x ;
void main() {

   TRISA=1 ;
   TRISd = 0;
   PORTd= 0 ;

   delay_ms(200);
    LCD_Init();
    LCD_Out(1, 1, "Speed In RPM:");
    TMR0H = TMR0L = 0;

     T0CON=96;

 delay_ms(2000);



  while(1) { x = (TMR0H<<8 ) + TMR0l;

      inttostr (x,lcd);

      lcd_out(2,1,lcd);
      delay_ms (2000);



   }

 }
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:

Thread Starter

mhghost

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

Rich (BB code):
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

  char txt2[10];
  char txt1[10];
  int  x=0;
  int y=0;
  int q =0;
   void main(){
   TRISB =0;

    Lcd_Init();
    delay_ms(2000);
    lcd_cmd( _LCD_CURSOR_OFF);
    T0CON =0b10001111;
    lcd_out (1,1,"time is ");
    lcd_out(2,1,"m=0");
    lcd_out(2,9,"s=0");
  while(1){
  


    //while(tmr0h < 0b00000001){}
    
    
    while(tmr0l < 0b11111111){}
    lcd_out (1,1,"time is ");
    x++;
    T0CON =0b00001111;

    tmr0h=0;
    tmr0l=0;
    T0CON =0b10001111;

  if(x==38){x=0;q++;}
  if(q==60){q=0;y++;}

  inttostr(q,txt1);
  inttostr(y,txt2);
  ltrim(txt1);
  ltrim(txt2);
  lcd_out(2,1,"m=");
  lcd_out_cp(txt2);
  lcd_out(2,9,"s=");
  if(q<10){ lcd_out_cp("0");}
  lcd_out_cp(txt1);


}   }
 
Last edited by a moderator:

Thread Starter

mhghost

Joined May 16, 2013
6
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
 

tshuck

Joined Oct 18, 2012
3,534
from page 107 in the datasheet:
TMR0H is not the high byte of the timer/counter in 16-bit mode, but is actually a buffered version of the high byte of Timer0 (refer to Figure10-2). The high byte of the Timer0 counter/timer is not directly readable nor writable. TMR0H is updated with the contents of the high byte of Timer0 during a read of TMR0L. This provides the ability to read all 16-bits of Timer0 without having to verify that the read of the high and low byte were valid due to a rollover between successive reads of the high and low byte.
You have to read the low bye in order for the high byte buffer to be loaded with the current value.
 
Top