View Full Version : Hardware Timer Delay
kwabena
12-14-07, 03:00 AM
Sir / Madam
How do i modify the code below for the characters to be
sent to the console window with 2 seconds Hardware timer delay,
with respect to NMIX0016.
#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h
#include clib\fputc.c
main()
{
int i;
/* print A to Z to serial */
for(i=0x41; i < 0x5A; i++)
fputc(i,stdout);
/* back to monitor prompt */
#asm
LJMP H'30
#endasm
}
nmitech
12-14-07, 12:17 PM
Please see the Timer tutorial on the web site below,
http://www.8052.com/tuttimer.phtml
Look to me, you can import the Detecting Timer Overflow assembly code in to your program using compiler directives below,
#asm
/* assembly code here */
#endasm
and add value counts on your outer loops to get your desire delay time
kwabena
01-04-08, 03:45 AM
Dear sir
I modify The TINYTEST code to print
characters every one seconds, but
when i compile the code it generate
error please below is the code. What
should i do to have it compile and execute
as i wish. Thanks
#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h
#include clib\fputc.c
int i;
One_Second();
fms();
/*..................................................................*/
main()
{
for(i=0x41; i < 0x5A; i++)
{
fputc(i,stdout);
One_Second();
}
}
/*..................................................................*/
One_Second()
{
unsigned char d;
/*/ Call fms() twenty times */
for (d = 0; d < 20; d++)
{
fms();
}
}
/*..................................................................*/
fms()
{
/*/ Configure Timer 0 as a 16-bit timer */
TMOD &= 0xF0;
TMOD |= 0x01;
ET0 = 0;
/* / Values for 50 ms delay */
TH0 =0x3C;
TL0 =0xB0;
TF0 =0;
TR0 =1;
while (TF0 == 0);
TR0 = 0;
}
nmitech
01-07-08, 03:11 PM
#include clib\common51.c
#include clib\syslib51.c
#include clib\stdio.h
#include clib\fputc.c
#include clib\iosfr.c
#define TCON 0x88
#define TMOD 0x89
#define TL0 0x8A
#define TH0 0x8C
#define IEN0 0xA8
/* --- SmallC doesn't support header prototype functions --- */
/*
One_Second();
fms();
*/
/*................................................. .................*/
main()
{
int i;
/* Configure Timer 0 as a 16-bit timer */
/* TMOD &= 0xF0; TMOD |= 0x01; */
OUTSFR(TMOD, (INSFR(TMOD) & 0xF0) | 0x01);
/* disable TMR0 OVFL interrupt */
/* ET0 = 0; */
OUTSFR(IEN0, INSFR(IEN0) & 0xFD);
for(i=0x41; i < 0x5B; i++)
{
fputc(i,stdout);
One_Second();
}
/* go back to monitor prompt */
#asm
LJMP H'30
#endasm
}
/*................................................. .................*/
One_Second()
{
int d;
/* Call fms() twenty times */
for (d = 0; d < 20; d++)
{
fms();
}
}
/*................................................. .................*/
fms()
{
/* Values for 50 ms delay */
/* TH0 =0x3C; */
OUTSFR(TH0,0x3C);
/* TL0 =0xB0; */
OUTSFR(TL0,0xB0);
/* clear ovfl flag & start timer */
/* TF0 =0; TR0 =1; */
OUTSFR(TCON, ((INSFR(TCON) & 0xDF) | 0x10));
/* wait till ovfl flag set */
/* while(TF0 == 0); */
while ((INSFR(TCON) & 0x20) == 0);
/* stop timer */
/* TR0 = 0; */
OUTSFR(TCON, INSFR(TCON) & 0xEF);
}
FYI: Address Registers information are in the document link below,
http://www.newmicros.com/store/product_manual/nmix-0016-oem.html
vBulletin v3.0.7, Copyright ©2000-2012, Jelsoft Enterprises Ltd.