Question: I wrote this code to create a 1 0 hour delay on 8 0 5 1 microcontroller and everytime the timer overflows using interrupt increment
I wrote this code to create a hour delay on microcontroller and everytime the timer overflows using interrupt increment an overflow counter and display that on segment display in hexadecimal but i am not able to display it on that as i am getting on all digit bits. I have attached the image of proteus simulation too. Please give me the correct code and test it on proteus too on your side.
#include
#define TIMERSTARTVALUE xCB Timer start value for ms
#define MAXCOUNT Counter limit for hour delay
segment display mapping common cathode
unsigned char hextoseg
xC
xF
xA
xB
x
x
x
xF
x
x
x A
x B
xC C
xA D
x E
xE F
;
Port definitions
sbit DIGIT P;
sbit DIGIT P;
sbit DIGIT P;
sbit DIGIT P;
unsigned int counter ; Timer overflow counter
void TimerInitvoid;
void displayHexunsigned int value;
void delaymsunsigned int ms;
void TimerISRvoid;
void main
TimerInit; Initialize Timer
while
if counter MAXCOUNT
TR; Stop the timer when MAXCOUNT is reached
while
displayHexcounter; Display final value continuously
displayHexcounter; Continuously display the counter value
void TimerInitvoid
TMOD x; Timer Mode bit timer
THTIMERSTARTVALUE & xFF; Load high byte
TL TIMERSTARTVALUE & xFF; Load low byte
ET; Enable Timer interrupt
EA ; Enable global interrupts
TR; Start Timer
void TimerISRvoid
THTIMERSTARTVALUE & xFF; Reload high byte
TL TIMERSTARTVALUE & xFF; Reload low byte
counter; Increment counter
void displayHexunsigned int value
unsigned char digits;
unsigned char i;
Extract each nibble from the bit value
digitsvalue & xF;
digitsvalue & xF;
digitsvalue & xF;
digits value & xF;
Sequentially display each digit
for i ; i ; i
DIGIT DIGIT DIGIT DIGIT; Disable all digits
switch i
case : DIGIT; break;
case : DIGIT; break;
case : DIGIT; break;
case : DIGIT; break;
P hextosegdigitsi; Output segment data
delayms; Small delay
void delaymsunsigned int ms
unsigned int i j;
for i ; i ms; i
for j ; j ; j; Approx ms delay at MHz
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
