• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

8051 Up Counter Verification Needed

Status
Not open for further replies.

Frosty_47

New Member
Hello, can some one plz verify my code below to be correct as I have no means of making sure it is at the moment. Thanks

The task is to write a program that causes Port 1 to act as an 8-bit up counter. Include a 500msec delay (not including overhead) to slow the count sufficiently to observe in hardware. Use Timers to produce the delay.

Here is my code (based on 12Mhz XTAL):

CLR A
START: MOV R2,#10

BACK: MOV TMOD,#01 ;Timer 1 Mode 1
MOV TL1,#0B0H ;TL1 = BOH, Low Byte
MOV TH1,#3CH ;TH1 = 3CH, High Byte
SETB TR1 ;Start Timer

HERE: JNB TF1,HERE ;Stay here until timer rolls over
CLR TR1 ;Stop Timer 1
CLR TF1 ;Clear timer flag
DJNZ R2,BACK ;repeat this 10 times to get 500msec delay

MOV P1,A ;mov A to P1
INC A
SJMP START

;Calculations
;500msec = 500,000uS = 10 * 50000 = 65536 - 50000 = 3CB0H
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top