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

Thu Jun 11 2020, 06:27 AM
anudee
sir could please send the code for I2C and wifi interfacing with 8051
scena
Tue May 19 2020, 10:29 PM
Does anyone have microcontroller programming software for STC15F104W (core 8051, 4 k, 128 byte, 6 I/O pin, UART ... DIL8), that works?
Sat May 02 2020, 07:38 PM
Tamu Gurung
Hi I am looking for a assembly language program for a digital decimal counter. Time counts max limit of 2 mins starting from 2.00 mins and ending at 0.00. time is to be displayed on 4 7-segment LED displays. Edsim51 simulator to be used. Thanks
Wed Mar 25 2020, 01:39 PM
Tajammul
Sir kindly send the code file i2c for 8051
ExperimenterUK
Fri Mar 13 2020, 10:36 PM
@ Rohitnani,ABEBE..which project ?
Fri Mar 13 2020, 12:55 PM
ABEBE
how can get hadwere of this project
Rohitnani
Sat Mar 07 2020, 05:11 PM
Sir, Could you please send me the zip file input password....
Wed Feb 26 2020, 04:58 PM
Peter Parker
Is it possible to send multiple messages using only 1 GSM module?
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.

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 47, Members: 0 ...

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

Members: 38215
Newest member: Mirza123
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jul 01 2020, 11:07 PM
PS: I am a new learner thats why my question may s...
Mirza123 Avatar
Posted By Mirza123
Wed Jul 01 2020, 02:05 PM
Thanks for the assistance. I have read the data sh...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jul 01 2020, 10:12 AM
See section 15 (Ports) of the data sheet. ...
wimac Avatar
Posted By wimac
Tue Jun 30 2020, 10:05 AM
How did you know that it is not 8051. Mirza123It i...
Mirza123 Avatar
Posted By Mirza123
Tue Jun 30 2020, 08:39 AM
It seems ports on the AT89LP2052 is not like on th...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jun 30 2020, 08:34 AM
It seems ports on the AT89LP2052 are not like on t...
Mirza123 Avatar
Posted By Mirza123
Thu Jun 25 2020, 04:07 PM
Hello!i am trying to use AT89LP2052 ( AT89LP2052 h...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jun 17 2020, 09:42 PM
It is about capacitor? i should put it between Vcc...
cerouno Avatar
Posted By cerouno
Wed Jun 17 2020, 10:37 AM
Take another look at the power supply to the LCD.A...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jun 17 2020, 02:01 AM
Take another look at the power supply to the LCD.A...