Discussion in "8051 Discussion Forum" started by    wounder    Jan 25, 2020.
Sat Jan 25 2020, 07:14 AM
#1
I have a 8051 micro controller ,it has timer0,1,2,3 with different modes.

in timer0,mode0, i got a sample code (as shown below).

from that code

TH0_INIT=0xFC //[email protected]=12MHz, Period = (10.85/2) [email protected]=22.1184MHz TL0_INIT=0x0F

both TH0,TL0 load with hex values..but could not derive these values from equation below .. (https://exploreembedded.com/wiki/5.8051_Timer_programming) Could you please tell me ,how these hex values derive ??

tick = (1/(Fosc/12)

tick = 12/Fosc$$ For Fosc == 11.0592Mhz, the tick time will be

tick = 12/11.0592M = 1.085069444us = 1.085us

Now the Timer value for the required delay can be calculated as below.

Delay = TimerCount * tick

Count = (Delay/tick)

RegValue = TimerMax- Count RegValue = TimerMax-(Delay/tick) = TimerMax - (Delay/1.085us)

RegValue = TimerMax-((Delay/1.085) * 10^6)$$


#include "SFR_Macro.h"
#include "Function_define.h"

#define TH0_INIT 0xFC //[email protected]=12MHz, Period = (10.85/2)
[email protected]=22.1184MHz
#define TL0_INIT 0x0F


void Timer0_ISR (void) interrupt 1 //interrupt address is 0x000B
{
TH0 = TH0_INIT;
TL0 = TL0_INIT;
P12 = ~P12; // GPIO
toggle when interrupt
}



void main (void)
{
TMOD = 0XFF;
Set_All_GPIO_Quasi_Mode;
TIMER0_MODE0_ENABLE;


clr_T0M;
clr_T1M;

TH0 = TH0_INIT;
TL0 = TL0_INIT;


// set_ET0; //enable Timer0 interrupt
//enable Timer1 interrupt
set_EA; //enable interrupts

set_TR0; //Timer0 run


while(1)
{
TH0 = TH0_INIT;
TL0 = TL0_INIT;
set_TR0;
while(!TF0);
clr_TR0;
P12 = ~P12;
TF0 = 0 ;
}
}
Sat Jan 25 2020, 11:05 PM
#2
For a 12MHz crystal using a normal divided by 12 clock.

For a 5mS delay I get
TH0_INIT=0xEC
TL0_INIT=0x78
What do you get ?

The program you posted uses polling and an interrupt to monitor the timer
and toggle P12, choose one, you can't (at least shouldn't) do both.

Get Social

Information

Powered by e107 Forum System

Conversation

Sun Mar 29 2020, 12:49 PM
osgppuwf
k2ArIsmN'));select pg_sleep(5.188); --
Sun Mar 29 2020, 12:48 PM
osgppuwf
NvmPD1e2';select pg_sleep(15.564); --
Sun Mar 29 2020, 12:48 PM
osgppuwf
-1);select pg_sleep(5.188); --
Sun Mar 29 2020, 12:48 PM
osgppuwf
rxLwvLCq'; waitfor delay '0:0:15.564' --
Sun Mar 29 2020, 12:48 PM
osgppuwf
-1); waitfor delay '0:0:5.188' --
Sun Mar 29 2020, 12:48 PM
osgppuwf
(select(0)from(select(sleep(15.564)))v)/*'+(select(0)from(select(sleep(15.564)))v)+'"+(select(0)from(select(sleep(15.564)))v)+"*/
Sun Mar 29 2020, 12:48 PM
osgppuwf
-1" OR 3*2>(0+5+515-515) --
Sun Mar 29 2020, 12:48 PM
osgppuwf
-1" OR 3+515-515-1=0+0+0+1 --
Sun Mar 29 2020, 12:48 PM
osgppuwf
-1' OR 3*2>(0+5+797-797) or 'gbmSTkol'='
Sun Mar 29 2020, 12:48 PM
osgppuwf
-1' OR 3+797-797-1=0+0+0+1 or 'gbmSTkol'='

Downloads

Comments

AndreySem
Mon Mar 30 2020, 01:35 AM
vityaCar
Sat Mar 28 2020, 11:21 PM
DeloresGrinc
Fri Mar 27 2020, 03:27 AM
Alexeyatola
Fri Mar 27 2020, 02:37 AM
RitaCar
Wed Mar 25 2020, 01:19 PM
BarbaraJaw
Tue Mar 24 2020, 04:38 PM
Rteredesai
Sun Mar 22 2020, 12:48 AM
engr_tariq
Wed Mar 18 2020, 04:18 AM

Online

Guests: 38, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 01:37 AM

Members: 38136
Newest member: AndreySem
Forum Activity
PHANTOM28 Avatar
Posted By PHANTOM28
Fri Feb 28 2020, 10:25 AM
Hi.I hope you all can help me. I am relatively ne...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Feb 21 2020, 05:05 PM
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Feb 21 2020, 04:45 AM
Yes you can do that.1. Create a channel @Thingspea...
ananyagupta Avatar
Posted By ananyagupta
Thu Feb 20 2020, 03:58 AM
With regards to the particular characters sent to ...
sarrahjuzar Avatar
Posted By sarrahjuzar
Wed Feb 19 2020, 04:24 AM
I have a gsm module sim900a and dht22 connected to...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Feb 18 2020, 04:52 PM
figureyang Avatar
Posted By figureyang
Tue Feb 18 2020, 04:59 AM
figureyang Avatar
Posted By figureyang
Tue Feb 18 2020, 04:50 AM
wounder Avatar
Posted By wounder
Mon Feb 10 2020, 03:32 AM
From below sample code for nuvoton 8051 timer0 mod...
Just4Fun Avatar
Posted By Just4Fun
Sat Feb 01 2020, 09:20 AM
If you want to use a CH55x MCU there isn't any adv...