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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
04/08/04 23:53
Read: times


 
#68221 - A broblem in serial communication
I wrote this code for Serial communication bet PC and MC to send a charachter from the PC to 89c52 MC,I'm using a c++ program on the PC to write to port 2f8(comm2):
C program:
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
void main()
{
int choice;
char ch;
cout<<"Enter your port 1-Comm1 2-Comm2"<<endl;
cin>>choice;
switch(choice)
{
case 1:
outportb(0x3fb,0x83); //Set in the bit 7(Divisor Latch) LCR(Line Ctrol Register)
outportb(0x3f9,0x0c); //Put in divisor MSB 30h
outportb(0x3f8,0x00); //Put in divisor LSB 00h
outportb(0x3fb,0x03); //Reset the bit to make the 2f8 act again as comm port
Rep: ch=getche();
if(ch==27)
exit(0);
outportb(0x3f8,ch);
goto Rep;
break;
case 2:
outportb(0x2fb,0x83); //Set in the bit 7(Divisor Latch) LCR(Line Ctrol Register)
outportb(0x2f9,0x30); //Put in divisor MSB 30h
outportb(0x2f8,0x00); //Put in divisor LSB 00h
outportb(0x2fb,0x03); //Reset the bit to make the 2f8 act again as comm port
Rep1: ch=getche();
if(ch==27)
exit(0);
outportb(0x2f8,ch);
goto Rep1;
break;
}

}
Assembly:
org 0
ljmp Main
org 023h
ljmp Serial
org 30h
Main: mov A,#55h
mov TMOD,#20h
mov TH1,#0f4h
mov SCON,#50h
mov IE,#10010000b
setb TR1
mov P1,A
Over: mov P0,A
mov P2,A
acall Delay
cpl A
sjmp Over
org 100h
Serial: push PSW
push ACC
mov A,SBUF
mov P1,A
clr RI
pop ACC
pop PSW
reti
Delay: mov R3,#10
Again: mov R4,#200
Back: mov R5,#230
Here: djnz R5,Here
djnz R4,Back
djnz R3,Again
ret
end
The part of complementing o/p of ports works excellent but the part of serial comm., when i type a character the o/p of port1 is zeros, what is the problem, all connections is right i read the o/p's on LEDs

List of 11 messages in thread
TopicAuthorDate
A broblem in serial communication            01/01/70 00:00      
   Too many unknowns!            01/01/70 00:00      
      RE: Too many unknowns!            01/01/70 00:00      
   RE: A broblem in serial communication            01/01/70 00:00      
      RE: A broblem in serial communication            01/01/70 00:00      
   RE: A broblem in serial communication            01/01/70 00:00      
      RE: A broblem in serial communication            01/01/70 00:00      
         RE: A broblem in serial communication            01/01/70 00:00      
            RE: A broblem in serial communication            01/01/70 00:00      
      RE: A broblem in serial communication            01/01/70 00:00      
         RE: A broblem in serial communication            01/01/70 00:00      

Back to Subject List