Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8051 coding problem for a light bulb control

Status
Not open for further replies.

Rockyvud

Newbie level 3
Newbie level 3
Joined
Nov 6, 2006
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,307
I have been trying to control a light bulb through computer interface and usign 8051 microcontroller.I think i am wrong somewhere in microcontroller programming,can someone tell me where? following is the program

org 00h
mov p2,#00H
mov tmod,#20H
mov scon,#50H
mov th1,#
setb tr1
scan:
jnb ri,$
mov p2,sbuf
clr ri
jmp scan
end,
 

Re: 8051 coding problem

What is your BaudRate ..
MOV TH1,# what?

Code:
                       1    $NOPAGING
                       2    $MOD252
                       3    
0000                   4            org 00h
                       5    
0000 75A000            6            mov p2,#00H 
0003 7404              7            MOV A, #04h             ; 9600bps ..
0005 120012            8            LCALL Ser_Setup
                       9     
0008                  10    scan: 
0008 3098FD           11            jnb ri,$ 
000B 8599A0           12            mov p2,sbuf 
000E C298             13            clr ri 
0010 80F6             14            jmp scan
                      15    
                      16    ; =====================================================================
                      17    ; Initialize Serial communications  A=Baud Rate
                      18    ; With cristal oscillator of 11,059,200 value for auto-reloded Timer1 is calculated using the
                      19    ; following formula: 256-57600/BaudRate=TH1
                      20    ; Full formula: 256-[2pwrSMOD/32]*[SC/(12*BaudRate)]
                      21    
0012                  22    Ser_Setup:      
0012 758780           23                    MOV     PCON, #80h
0015 759852           24                    MOV     SCON, #52h
0018 758920           25                    MOV     TMOD, #20h
001B 900024           26    SetNewBaud:     MOV     DPTR, #BAUDRATE
001E 93               27                    MOVC    A, @A+DPTR
001F F58D             28                    MOV     TH1, A
0021 D28E             29                    SETB    TR1
0023 22               30                    RET
                      31    
0024 FF               32    BAUDRATE:       DB   0FFh               ; 57600         0
0025 FE               33                    DB   0FEh               ; 28800         1
0026 FD               34                    DB   0FDh               ; 19200         2
0027 FC               35                    DB   0FCh               ; 14400         3
0028 FA               36                    DB   0FAh               ; 9600          4
0029 F4               37                    DB   0F4h               ; 4800          5  
002A E8               38                    DB   0E8h               ; 2400          6
002B D0               39                    DB   0D0h               ; 1200          7
002C A0               40                    DB   0A0h               ; 600           8  
002D 40               41                    DB   040h               ; 300           9
                      42    
                      43    
                      44    ; ====================================================================
                      45    
                      46            end

VERSION 1.2h ASSEMBLY COMPLETE, 0 ERRORS FOUND
BAUDRATE . . . . . . . . . . . .  C ADDR  0024H  
P2 . . . . . . . . . . . . . . .  D ADDR  00A0H  PREDEFINED  
PCON . . . . . . . . . . . . . .  D ADDR  0087H  PREDEFINED  
RI . . . . . . . . . . . . . . .  B ADDR  0098H  PREDEFINED  
SBUF . . . . . . . . . . . . . .  D ADDR  0099H  PREDEFINED  
SCAN . . . . . . . . . . . . . .  C ADDR  0008H  
SCON . . . . . . . . . . . . . .  D ADDR  0098H  PREDEFINED  
SER_SETUP. . . . . . . . . . . .  C ADDR  0012H  
SETNEWBAUD . . . . . . . . . . .  C ADDR  001BH  NOT USED  
TH1. . . . . . . . . . . . . . .  D ADDR  008DH  PREDEFINED  
TMOD . . . . . . . . . . . . . .  D ADDR  0089H  PREDEFINED  
TR1. . . . . . . . . . . . . . .  B ADDR  008EH  PREDEFINED

Regards,
IanP
 

    Rockyvud

    Points: 2
    Helpful Answer Positive Rating
8051 coding problem

Baud rate is 9600 bps.




MOV TH1,# -3
Is this right for getting 9600 baudrate?
 

Re: 8051 coding problem

Rockyvud wrote:
MOV TH1,# -3
Is this right for getting 9600 baudrate?

MOV TH1,# -3 is right for getting 9600 baudrate if fXTAL = 11.0592 MHz and if bit SMOD == 0. (SMOD = PCON.7)
 

8051 coding problem

Try these,

MOV SCON,#50H
MOV TMOD,#20H
MOV TH1,#0FDH ;for 9600 baud rate n 11.0592MHZ
SETB TR1

Added after 1 minutes:

ALSO I USE TO CALL SOME DELAY ROUTINE BEFORE SBUF (if there is a loop)
 

8051 coding problem

Basic '51 UART troubleshooting:
**broken link removed**

wek
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top