Microcontroller › 8051 › Help for serial communication
- This topic has 3 replies, 2 voices, and was last updated 13 years, 1 month ago by
AJISH ALFRED.
-
AuthorPosts
-
January 4, 2013 at 8:57 am #2047
Radhika
ParticipantHello,
I am developing a controller based serial communication project in which I am sending two data to serial port. One is for selecting output pin & second for getting different timer delay value to generate different delayed pulses. My problem is that I can’t properly send data to serial port please help me if anyone have idea about this.
I am using AT89c52 controller & max232 for level converter. Here is my code.
Please help me..
Thanks in advance.
My code:
#include <AT89X52.H>#include<stdio.h>sbit Pulse1=P1^0;sbit Dir1=P1^1;sbit Pulse2=P1^2;sbit Dir2=P1^3;sbit a=P0^0;sbit b=P0^1;sbit c=P0^2;sbit d=P0^3;msdelay(unsigned int value);getdata();unsigned int value;getdata(){if(b) // For Dir1Dir1=1;if(d) // For Dir2Dir2=1;if((!a)&(!c)){Pulse1=0;Pulse2=0;}if(a&(!c)){Pulse1=1;msdelay(value);Pulse1=0;msdelay(value);}if((!a)&c){Pulse2=1;msdelay(value);Pulse2=0;msdelay(value);}if(a&c){Pulse1=1;Pulse2=1;msdelay(value);Pulse1=0;Pulse2=0;msdelay(value);}}void recive(void) interrupt 4{unsigned int mybyte,i;while(1){if(RI==1){P0=0xFF;ACC=0x00;P1=0x00;}if(i==0){mybyte=SBUF;ACC=mybyte;P0=ACC;RI=0;i++;}if(i==1){mybyte=SBUF;ACC=mybyte;value=ACC;RI=0;i=0;}getdata();}}void main(){P1=0x00;EA=1;ES=1;SCON = 0x50; // mode 1, 8-bit UART, enable receiverTMOD = 0x20; // timer 1, mode 2, 8-bit auto-reloadTH1 = 0xFD; // for 9600 baud rate 0xFDTR1 = 1; // run timer 1while (1){}}//delay functionmsdelay(unsigned int value){unsigned int x,y;for(x=0;x<value;x++)for(y=0;y<1275;y++);}
January 5, 2013 at 6:24 pm #8905AJISH ALFRED
ParticipantHi Radhika,
Where are you trying to display the data? Are you getting junk data or simply nothing?
January 7, 2013 at 11:35 am #8914Radhika
ParticipantI am dispiaying data on Led connected toPort1 but when i enter two data it accepts only one either 1st or 2nd data as input.
Here problem is in accepting 2nd input but i dnt know how to solve it… Please help me.
January 8, 2013 at 11:34 am #8920AJISH ALFRED
ParticipantYou are not calling any functions from your main function. Then how the code will it do something?
-
AuthorPosts
- You must be logged in to reply to this topic.