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.

corrupt data on lcd from serial interrupt

Status
Not open for further replies.

beyondH

Member level 5
Joined
Oct 21, 2011
Messages
91
Helped
17
Reputation
34
Reaction score
15
Trophy points
1,288
Location
delhi
Activity points
1,960
hellow experts,,
kindly help me(i think i have gt confused..)
My program:

org 0023h
jb ti,transmit
jb ri,recieve

then doing

mov sbuf,#'A'
acall delay

mainloop:
sjmp mainloop

transmit:
mov a,sbuf
acall senddata
acall sdelay

clr ti
reti

recieve:
mov a,sbuf
acall senddata
acall sdelay
clr ri
reti



the moment i put 'A' into the sbuf, interrupt is called but "corrupted data" is displayed on lcd....(means something wrong with transmit subroutine)
while
if I connect with serial port of computer and sends characters through keyboard,, they are clearly shown on lcd...(means recieve routine is correct)

kindly point out the possible errors...
hardware is OK(lcd in initiallised as recieve subroutine is perfectly running)

https://www.edaboard.com/threads/229264/

(by mistake, I posted this into another thread......)


initial letters are those which i have encoded into the program..i.e.
mov sbuf,'A'
mov sbuf,'B'

and afterwards the letters are from the keyboard(after connecting to pc serial port) which is working fine....
 

i think u are not converting the data to ascii you are directly sending the binary data to SBUF which will not work and secondly , the data in SBUF should be inverted
void send_data()
{
port_data = ~P2 & 0x0F; //read data from port2 and send to serial port
data_lower = port_data % 10;
data_convert_lower = data_lower | 0x30; //convert to ascii code 0x30 to 0x39 for digits 0 to 90
data_sent = data_convert_lower;
SBUF = data_sent; //store in serial buffer
while(TI==0); //wait untill data is sent serially till TI becomes 1
TI=0; //make TI = 0 to recieve new byte
}
 

bro, first of all thnxx for the help...

but the point is that if i connect my uC to pc and open any terminal software,, I am able to see them very clearly i.e. my A is coming to the terminal
that means ki sending of "A" is ok, but as soon as it completes sending of "A" it should goto the transmit buffer(as ti is raised)..and there I try to copy sbuf to a(accumulator) and then display it on lcd..now this is defective...

I hope now i have more clearly shown my problem....
 

2011-11-07 17.10.45.jpg2011-11-07 17.13.45.jpg
 

I am trying to understand what you wish to do so that I can propose some solution.
1. You are sending some characters from microcontroller to PC.
2. You wish to see the Same on LCD display connected to the microprocessor.
Is it right or something else !
Also you are using 89S52, you may add ISP Programmer connection on your board so that you can modify the code and check the effect easily. This will help the development faster.
 

yes sir, you are getting it right..
thnx for your suggestions for isp programmer....

the problem is that anything coming into the "transmit buffer" is not getting displayed on the lcd...
for debugging purpose: I connected a led to a pin and inside the transmit interrupt handler routine I blinked it so that I may come to know that controller is coming to that part correctly..
result: the led was blinking accurately...
the data is also coming to the lcd but in corrupted form...
386586_10150520823860744_552630743_11480527_1337897222_n.jpg

initial corrupted ones are the response(from transmit interrupt) from the lcd, rest ones which are OK are coming from the recieve serial interrupt...
 

There is some problem with your program.
The listing in first post is not complete.
Is interrupt really needed here?
uC is sending data to computer serially, is it receiving also from PC?
Because what you are sending to PC can at the same time be displayed on LCD.
 

yes sir,, you are right..
it can be done that way also...
but I wanted to check that whenever transmit interrupt is called it saves the value in it or not??
till now, I am not able to see that,,

mov ie,#10010101b ;enabled my hardware interrupts too along with the serial
mov ip,#00h ;no priority
mov tmod,#20h
mov th1,#0fdh
mov scon,#50h
setb tr1

as per my thinking my code is correct but still the lcd is not showing the data..(even this is of no use...but still why this isn't happening)
 

The one who understands this may give a useful response:
but I wanted to check that whenever transmit interrupt is called it saves the value in it or not??
till now, I am not able to see that,,

as per my thinking my code is correct but still the lcd is not showing the data..(even this is of no use...but still why this isn't happening)

This you may know better than any body else as you know your code
 

doubt::
sir, I have seen many codes on internet,, everyone uses Tx for polling and Rx as interrupt....
everyone avoids Tx for some reasons(I dont know)...why?????

and in my previous post, I want to ask that if you write:

mov sbuf,'A'
-->transmit interrupt will be called and transmit interrupt is defined as follows:
transmit:
mov a,sbuf
acall senddata ;senddata to what is in "a" to lcd
reti

but still junk values are shown...
can you please try it out sir??
 

Dear beyondH no need to use "Sir"
The fact is that your problem is not clearly defined.
All members try to address to the point or question raised to their best.
My recent post indicates that we dont know your code.
If you could share as to what steps exactly you wish to implement and also what is the code you are implementing the desired action, this will help members to provide a to the point working solution.
Try to attend to it in modular fashion. Keep LCD code separate and rest of the logic separate, also try to find out whether you actually need interrupt in this?
 

In my view .....you should try ot add -48 to the characters received based on your requirement such that it will get out off your ascii char send by hyperterminal
 

Code:
;hardware declarations
                        lcdport equ p2
                        lcdrs   equ p3.6
                        lcden   equ p3.7 
                        stackval equ 70h
                        w       equ 31h
                        y       equ 32h 
                        z       equ 33h
                        
;start of program
                        
                        org 000h
                        ajmp poweron
                        org 0003h
                        reti
                        org 000bh
                        reti
                        org 0013h
                        reti
                        org 001bh
                        reti
                        org 0023h
                        jb ri,recieve
                        jb ti,transmit                                                

        poweron:        mov sp,#stackval
                        mov p0,#0ffh 
                        mov p1,#00h               
                        mov p2,#0ffh
                        mov p3,#0ffh
                        mov ie,#90h
                        mov ip,#0001000b
                       
                        acall longdelay                        
                        acall init
                        acall longdelay
                        mov dptr,#msg
                        acall sendmsg
                        acall longdelay

                    
                        mov tmod,#20h
                        mov th1,#0fdh
                        mov scon,#50h
                        setb tr1
                        
                        mov a,#02h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#01h
                        acall sendcmd
                        acall secdelay               
                        
                        mov sbuf,#65d
                        acall secdelay
                        
                        mov sbuf,#84d
                        acall secdelay
                        
                        mov sbuf,#0dh
                        acall secdelay
                        
                        mov sbuf,#0ah
                        acall secdelay
                        acall one_sec_delay
                        
        mainloop:      
                        sjmp mainloop
        
        transmit:      
                        mov a,sbuf
                        acall senddata
                        clr ti
                        reti

        recieve:       
                        mov a,sbuf
                        acall senddata       
                        clr ri
                        reti

                        ;INITIALLISATION OF LCD
        init:           mov a,#28h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#28h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#28h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#06
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#0eh
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#02h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#01h
                        acall sendcmd
                        acall secdelay
                        ret


        sendcmd:        clr lcdrs
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall secdelay
                        clr lcden
                        swap a
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall secdelay
                        clr lcden
                        ret


        senddata:       setb lcdrs
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall longdelay
                        clr lcden
                        swap a
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall longdelay
                        clr lcden
                        ret



        sendmsg:        mov r0,#0bh
                        mov r1,#00h
                loop:   acall longdelay
                        mov a,r1
                        movc a,@a+dptr
                        acall senddata
                        inc r1
                        djnz r0,loop
                        ret

        secdelay:
                        mov r5,#10d
 lab2:                  mov r6,#10d
 lab1:                  mov r7,#20d
 lab0:                  djnz r7,lab0
                        djnz r6,lab1
                        djnz r5,lab2
                        ret
                        
      longdelay:
                        mov r2,#20d
 lab3:                  mov r3,#20d
 lab4:                  mov r4,#20d
 lab5:                  djnz r4,lab5
                        djnz r3,lab4
                        djnz r2,lab3
                        ret

        one_sec_delay:
                                          
                        mov w,#20d
 lab9:                  mov y,#100d
 lab10:                 mov z,#100d
 lab11:                 djnz z,lab11
                        djnz y,lab10
                        djnz w,lab9
                        ret


                        org 300h
        msg:           db 'Beyond Hack' 


end

MY PROGRAM IS ABOVEMENTIONED::
I know that there is no need of interrupt for Tx,, but still,,
MY QUESTION::IS NOT POSSIBLE TO DISPLAY TO LCD WHATEVER IS IN SBUF DURING TRANSMIT INTERRUPT??(in case of recieve, it is working correct...as you can see in the picture above)

---------- Post added at 19:04 ---------- Previous post was at 18:59 ----------

@milind.a.kulkarni,
sending through terminal communictaion software(in my case: it is putty) is fine,, as you can see in the above picture, 123456 are sent by the terminal software,, but the initial junk values are sent by the uC to the terminal and during the transmit interrupt, I want them also to be displayed on lcd....

You may refer to my code above...
 
Last edited by a moderator:

Code:
;hardware declarations
                        lcdport equ p2
                        lcdrs   equ p3.6
                        lcden   equ p3.7 
                        stackval equ 70h
                        w       equ 31h
                        y       equ 32h 
                        z       equ 33h
                        
;start of program
                        
                        org 000h
                        ajmp poweron
                        org 0003h
                        reti
                        org 000bh
                        reti
                        org 0013h
                        reti
                        org 001bh
                        reti
                        org 0023h
                        jb ri,recieve
                        jb ti,transmit                                                

        poweron:        mov sp,#stackval
                        mov p0,#0ffh 
                        mov p1,#00h               
                        mov p2,#0ffh
                        mov p3,#0ffh
                        mov ie,#90h
                        mov ip,#0001000b
                       
                        acall longdelay                        
                        acall init
                        acall longdelay
                        mov dptr,#msg
                        acall sendmsg
                        acall longdelay

                    
                        mov tmod,#20h
                        mov th1,#0fdh
                        mov scon,#50h
                        setb tr1
                        
                        mov a,#02h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#01h
                        acall sendcmd
                        acall secdelay               
                        
                        mov sbuf,#65d
                        acall secdelay
                        
                        mov sbuf,#84d
                        acall secdelay
                        
                        mov sbuf,#0dh
                        acall secdelay
                        
                        mov sbuf,#0ah
                        acall secdelay
                        acall one_sec_delay
                        
        mainloop:      
                        sjmp mainloop
        
        transmit:      
                        mov a,sbuf
                        acall senddata
                        clr ti
                        reti

        recieve:       
                        mov a,sbuf
                        acall senddata       
                        clr ri
                        reti

                        ;INITIALLISATION OF LCD
        init:           mov a,#28h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#28h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#28h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#06
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#0eh
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#02h
                        acall sendcmd
                        acall secdelay
                        
                        mov a,#01h
                        acall sendcmd
                        acall secdelay
                        ret


        sendcmd:        clr lcdrs
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall secdelay
                        clr lcden
                        swap a
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall secdelay
                        clr lcden
                        ret


        senddata:       setb lcdrs
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall longdelay
                        clr lcden
                        swap a
                        mov lcdport,a
                        acall secdelay
                        setb lcden
                        acall longdelay
                        clr lcden
                        ret



        sendmsg:        mov r0,#0bh
                        mov r1,#00h
                loop:   acall longdelay
                        mov a,r1
                        movc a,@a+dptr
                        acall senddata
                        inc r1
                        djnz r0,loop
                        ret

        secdelay:
                        mov r5,#10d
 lab2:                  mov r6,#10d
 lab1:                  mov r7,#20d
 lab0:                  djnz r7,lab0
                        djnz r6,lab1
                        djnz r5,lab2
                        ret
                        
      longdelay:
                        mov r2,#20d
 lab3:                  mov r3,#20d
 lab4:                  mov r4,#20d
 lab5:                  djnz r4,lab5
                        djnz r3,lab4
                        djnz r2,lab3
                        ret

        one_sec_delay:
                                          
                        mov w,#20d
 lab9:                  mov y,#100d
 lab10:                 mov z,#100d
 lab11:                 djnz z,lab11
                        djnz y,lab10
                        djnz w,lab9
                        ret


                        org 300h
        msg:           db 'Beyond Hack' 


end

MY PROGRAM IS ABOVEMENTIONED::
I know that there is no need of interrupt for Tx,, but still,,
MY QUESTION::IS NOT POSSIBLE TO DISPLAY TO LCD WHATEVER IS IN SBUF DURING TRANSMIT INTERRUPT??(in case of recieve, it is working correct...as you can see in the picture above)

---------- Post added at 19:04 ---------- Previous post was at 18:59 ----------

@milind.a.kulkarni,
sending through terminal communictaion software(in my case: it is putty) is fine,, as you can see in the above picture, 123456 are sent by the terminal software,, but the initial junk values are sent by the uC to the terminal and during the transmit interrupt, I want them also to be displayed on lcd....

You may refer to my code above...


Hi Byondh.....

I had did assembly programming long time back .....I think you need to do the following change mov sbuf ,a......bcz you need to transfer content of accumulator to SBUF not SBUF to accumulator ......try this out.....

Good luck
 

Hi Byondh.....

I had did assembly programming long time back .....I think you need to do the following change mov sbuf ,a......bcz you need to transfer content of accumulator to SBUF not SBUF to accumulator ......try this out.....

Good luck


sir,
as what i know(rectify me if i am wrong) interrupt is called whenever ti or ri is high..
so as soon as the instruction-->mov sbuf,'A'
is executed and 'A' is moved into the sbuf i.e. last bit moves ti is high and interrupt is called,,
and whatever is in is executed...
ryt??

now since i have moved 'A' into sbuf... that means character A is in sbuf..
so coming to transmit interrupt I am taking the value from sbuf to a(accumulator) and then calling the senddata subroutine....
what say sir??

---------- Post added at 22:16 ---------- Previous post was at 22:15 ----------

@ark5230--am i clear about my problem now from the above source code and the explanation??
 

sir,
as what i know(rectify me if i am wrong) interrupt is called whenever ti or ri is high..
so as soon as the instruction-->mov sbuf,'A'
is executed and 'A' is moved into the sbuf i.e. last bit moves ti is high and interrupt is called,,
and whatever is in is executed...
ryt??

now since i have moved 'A' into sbuf... that means character A is in sbuf..
so coming to transmit interrupt I am taking the value from sbuf to a(accumulator) and then calling the senddata subroutine....
what say sir??

---------- Post added at 22:16 ---------- Previous post was at 22:15 ----------

@ark5230--am i clear about my problem now from the above source code and the explanation??

Yes .....you are right.....In my view that is the case......r u tried it out ?........r u getting the results ?....

Please donot call me sir......all we are with equal level and try, contribute, shear and learn...

Regards,

Milind
 

I tried this, but no outcome...I dont know embedded C programming, so can you try it in C using transmit as interrupt as well along with the recieve interrupt...
 

hi beyondH i recall i also faced same problem even when i only recieved data in interrupt and then displayed it in main program i also got random display so if u go through my previous program u would find i used interrupt but i reseted RI and TI i main program hence i got data on LCD
 

@akshay985
bro, are you saying of this 123.JPG?
I mean in the serial initiallisation function you have set ti and ri as 0.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top