Displaying numbers on 16x2 LCD
Transmitter:
#define uchar unsigned char #define uint unsigned int #include<intrins.h> #include<reg52.h> #include<math.h> #include<stdio.h> void SendSS(void) { putchar(0xF0); } void SendData(int txbyte) { unsigned char G=(1<<0); int i,j,b,me; b = txbyte; for (i=0; i<2; i++) { me = 0; // manchester encoded txbyte for (j=0 ; j<4; j++) { me > > =2; if (b&G) me |= 0x40; // 1-> 0 else me |= 0x80; // 0-> 1 b > > =1; } putchar(me); } } void sercon(void) { SCON = 0x50; TMOD |= 0x20; TH1 = 0xE6; TR1 = 1; TI = 1; } void main() { sercon(); while(1) { SendSS(); SendData(0x42); SendSS(); } }
Receiver:
#include<intrins.h> // #include<reg51.h> // #include<math.h> // #include<stdio.h> // #include<1602.h> // unsigned char a[8]; unsigned char buffer[8]; int DecodeData(int encoded) { int i,dec,enc,pattern; enc = encoded; if (enc == 0xf0) // start/end condition encountered return 0xf0; dec = 0; for (i=0; i<4; i++) { dec > > =1; pattern = enc & 0x3; if (pattern == 0x1) // 1 dec |= 1 << 3; else if (pattern == 0x2) dec &= ~(1 << 3); // 0 else return 0xff; // illegal code enc > > =2; } return dec; } void sercon(void) { SCON = 0x50; TMOD |= 0x20; TH1 = 0xE6; TR1 = 1; TI = 1; /*clear the buffer */ } void main() { int dec; int dec1; int dec2; int dec3; int dec4; int data1; sercon(); init(); while(1) { data1 = getchar(); dec = DecodeData(data1); data1 = getchar(); dec = DecodeData(data1); dec1 = dec; data1 = getchar(); dec = DecodeData(data1); dec2 = dec; dec3 = dec2 << 4; dec4 = dec3 + dec1; writeCmd(0x80); sprintf(buffer,"%s",dec4); sendstring(buffer); }}
[ Edited Fri Jan 21 2011, 08:27 pm ]
try to do this way..send this string on uart and receive on other end
UUUUU$testUUUUU
send 5 'U' and then $ which means your start of data, when you receive $ on receiver end start reading data in a buffer, read 4 bytes and store in buffer then stop reading. display string on terminal.
make sure baudrate is around 4800bps or lesser 2400. Please try again.
Transmitter:
#include<intrins.h> #include<reg52.h> #include<math.h> #include<stdio.h> void sercon(void) { SCON = 0x50; TMOD |= 0x20; TH1 = 0xE6; TR1 = 1; TI = 1; } void main() { sercon(); while(1) { putchar(0x55); putchar(0x55); putchar(0x55); putchar(0x55); putchar(0x55); putchar(0x24); } }
Receiver:
#include<intrins.h> #include<reg51.h> #include<math.h> #include<stdio.h> #include<1602.h> unsigned char a[10]; unsigned char buffer[32]; void sercon(void) { SCON = 0x50; TMOD |= 0x20; TH1 = 0xE6; TR1 = 1; TI = 1; /*clear the buffer */ } void main() { sercon(); init(); while(1) { writeCmd(0x80); gets (a, sizeof(a)-1); sprintf(buffer,"%s",a); sendstring(buffer); }}
u use which module by which u get good communication
it may be a cause of ur problem that this module uses encoder and decoder
Am I right?
And I saw that encoder and decoder have 4 data pins. So every time they will send just 4bits of info? And on receiver side I'll have to make bit operations in order to conncet pair of 4bits?
But what's really strange is that I keep reveiving U's when I've even changed a program of transmitter. There is no temperature vaules but only UUU's.
[ Edited Sun Jan 23 2011, 04:07 am ]
I wrote an email to the manufacturer and they said those modules don't use encoding and decoding.
now it is verify that it can work without that
Well, I took a look at HT12E and HT12D micros. So as I understood, the data will come from I/O ports like P1, P2 and so on and Tx and Rx pins will work as flags and boudrate regulators but not as serial transmitter and receivers. Data transmitter in this case will be I/O ports.
Am I right?
And I saw that encoder and decoder have 4 data pins. So every time they will send just 4bits of info? And on receiver side I'll have to make bit operations in order to conncet pair of 4bits?
some encoder r of 4 bits and some r of 8 bis u can use 8 bits also
in 4 bit it send data in 4 bits and u has to divide no's in 2 nibbles send it one by one and at rx side u then make it byte again
But what's really strange is that I keep reveiving U's when I've even changed a program of transmitter. There is no temperature vaules but only UUU's.
this is strange if u not transmit then is u also receive U
post ur code that u test for this
And yes, I saw encoders and decoders which can encode and decode 8 bits.
may be its work
go through this thread it has same problem like u
http://www.8051projects.net/forum-t37768-0.html
[ Edited Sun Jan 23 2011, 09:30 pm ]