Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Sergey Meerovich
06/09/09 15:27
Read: 707 times


 
#165959 - transmit/recieve character by using 8051 and USART
Hi ,for everyone ,I'm new here .
I working with some kit that use 8051 that has connection by USART(8251) and connecttion with PC by protocol RS-232c ,I want to recieve/send data by using Windows program HyperTerminal (I never work with it till now) I wrote some code on Assembly(I'm not such a good programmer in Assembler)
in program my Usart already ready to send and recieved data and translate it to ASCII and viceversa to binary.

but how i send data from terminal (from hyperterminal) are the any command I need to write,
maybe I have mistakes in code you see that I must fix, how I continue my program?


code is..:

org 100h
command: mov dptr,#0ff17h ;address for controll word for 8255(programable port)
mov a,#89h ; the value of word(mode,port out,port in)
movx @dptr,a ; send the word to 8255
mov dptr,#0dd1bh ; address of 8254(timer/counter)
mov a,#36h ; value for counter
movx @dptr,a ; send it to 8254
mov dptr,#0ff18h ; the address of Port0 in 8254
mov a,#14h ; the value for devider the clocking (6.144Mhz/20)
movx @dptr,a ;
mov a,#0h ;
movx @dptr,a ;
mov dptr,#0ff1dh ;address of Usart
mov a,#0eeh ; value for Mode instruction:
movx @dptr,a ; send the Mode instruction
mov a,#37h ;Command Instruction for Usart(8251
movx @dptr,a ;send a command instructio
recieve: mov dptr,#0ff1d ;address of Usart
movx a,@dptr ;set value that Usart has to Accomulator
jnb acc.1,recieve ;checking if bit not set ,if not Usart not ready recieve data,so it's return to recieve
lcall BIN2ASC
mov dptr,#0ff1ch ;if it ready recieve data it's located in address 0ff1ch
movx a,@dptr ;mov it to Accumulator
mov b,a ;store it in B
send: mov dptr,#0ff1dh ;address of Usart
movx a,@dptr ;check if usart ready to send data
jnb acc.0,send ;by checking bit ,if not jump back to label send
lcall ASC2BIN
mov dptr,#0ff1ch ;if it ready recieve data it's located in address 0ff1ch
mov a,b ;get data back to a
movx @dptr,a ;send it out
mov dptr,#0ff14h ;get address of portA (leds ,7-Seg)
movx @dptr,a ;send a data to it
sjmp recieve




ASC2BIN: ;Convert from ASCII to Binary
MOV A,R2 ;Inputs: R2,R3
LCALL BIN ;Output: A
SWAP A ;R2 - M.S.D R3 - L.S.D
MOV R2,A
MOV A,R3
LCALL BIN
ADD A,R2
RET

BIN: CLR C
SUBB A,#3AH
JNC BIN2
ADD A,#0AH
RET
BIN2: ADD A,#3
RET



BIN2ASC:
MOV R4,A ;Convert from Binary to ASCII
SWAP A ;Input: A
LCALL ASC ;Outputs: R2,R3
MOV R2,A ;R2 - M.S.D R3 - L.S.D
MOV A,R4
LCALL ASC
MOV R3,A
RET

ASC: ANL A,#0FH
CLR C
SUBB A,#0AH
JNC ASC2
ADD A,#3AH
RET
ASC2: ADD A,#41H
RET




end


List of 12 messages in thread
TopicAuthorDate
transmit/recieve character by using 8051 and USART      Sergey Meerovich      06/09/09 15:27      
   Be sure your 8251 is fast enough      Richard Erlacher      06/09/09 18:42      
      conver ASCII to bin and viceversa and interface      Sergey Meerovich      06/10/09 03:53      
         translate ASCII to binary ? [edited]      Andy Neil      06/10/09 04:38      
            65 base 10 = 41 base 16      Per Westermark      06/10/09 04:43      
               Corrected!      Andy Neil      06/10/09 05:55      
         binary to hex      Per Westermark      06/10/09 04:40      
            Text representation of numbers      Andy Neil      06/10/09 05:48      
               connection with HyperLink      Sergey Meerovich      06/15/09 09:02      
                  unplug and plug      Erik Malund      06/15/09 09:05      
   Question about Polling method for send recieve data      Sergey Meerovich      06/16/09 01:02      
      yes, and no      Erik Malund      06/16/09 08:31      

Back to Subject List