Discussion in "8051 Discussion Forum" started by    wounder    Jan 25, 2020.
Sat Jan 25 2020, 12:14 PM
#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 ;
}
}
Sun Jan 26 2020, 04:05 AM
#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

Sat Feb 01 2020, 10:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.
Tue Jan 14 2020, 07:08 AM
shubham kharade
when i am trying to simulate the program in Proteus 8 professional, I am getting some errors as cannot find module file dhtxx.md can u help me
Tue Dec 17 2019, 01:44 PM
Devangi
hello..i am programming industrial timer using 8051 with 24lc64 eeprom. i have query in storing the 3 diff value in eeprom with enter button. can anyone share c code ?
Tue Dec 17 2019, 10:30 AM
Andrius
Hello. Can anyone share the code in Bascon and scheme in Proteus?
Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,

Downloads

Comments

sarrahjuzar
Wed Feb 19 2020, 09:13 AM
arun.sapro
Wed Feb 12 2020, 04:47 PM
prathmiyer
Tue Feb 11 2020, 11:12 AM
Just4Fun
Sat Feb 01 2020, 01:29 PM
Deepkumar
Thu Jan 30 2020, 03:52 PM
wounder
Sat Jan 25 2020, 12:09 PM
brucewilliams20
Thu Jan 23 2020, 11:47 AM
Nippy56
Sun Jan 19 2020, 02:13 AM

Online

Guests: 39, Members: 0 ...

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

Members: 38123
Newest member: sarrahjuzar
Forum Activity
sarrahjuzar Avatar
Posted By sarrahjuzar
Wed Feb 19 2020, 09:24 AM
I have a gsm module sim900a and dht22 connected to...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Feb 18 2020, 09:52 PM
figureyang Avatar
Posted By figureyang
Tue Feb 18 2020, 09:59 AM
figureyang Avatar
Posted By figureyang
Tue Feb 18 2020, 09:50 AM
wounder Avatar
Posted By wounder
Mon Feb 10 2020, 08:32 AM
From below sample code for nuvoton 8051 timer0 mod...
Just4Fun Avatar
Posted By Just4Fun
Sat Feb 01 2020, 02:20 PM
If you want to use a CH55x MCU there isn't any adv...
Just4Fun Avatar
Posted By Just4Fun
Sat Feb 01 2020, 01:51 PM
Hi all,I was curious to try out the CH552 MCU (805...
Deepkumar Avatar
Posted By Deepkumar
Thu Jan 30 2020, 05:36 PM
I want to send a text message in other than the En...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Jan 26 2020, 04:05 AM
For a 12MHz crystal using a normal divided by 12 c...
wounder Avatar
Posted By wounder
Sat Jan 25 2020, 12:14 PM
I have a 8051 micro controller ,it has timer0,1,2,...