|
|
View previous topic :: View next topic |
Author |
Message |
chin0609
Joined: 13 Sep 2011 Posts: 18
|
|
|
chin0609
Joined: 13 Sep 2011 Posts: 18
|
|
Posted: Sat Oct 01, 2011 7:13 am |
|
|
Any sample code for transmitter and receiver part? I just need to do eg. "when transmitter pin data high, receiver pin data also high". |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Oct 01, 2011 3:46 pm |
|
|
Well you could go to the website you linked too, then download the application (PR16 I think) which has code for both tx and rx coded in C. You'll have to translate it into CCS C but it is all there, you just have to read the information that Cytron supplies ! |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat Oct 01, 2011 4:23 pm |
|
|
I had a customer pay me to test if he could use this type of cheap gadget for a power monitoring instrument.
The links can be VERY noisy
and i found it failed pretty EZ when i tried to link ordinary RS_232 TTL level signals - ala PIC direct TX/RX.
The test it was not pretty unless the units were close enough to hook up with a wire anyway.
A custom NRZ code might fare better.
http://en.wikipedia.org/wiki/Non-return-to-zero
---
but when i found out that as a class these were tending NOT to be FCC approved - i bailed
good luck |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 01, 2011 5:16 pm |
|
|
Cytron has sample code for the Hi-Tech compiler for the RF transmitter
and receiver on this page:
http://www.cytron.com.my/viewProduct.php?pcode=PR16
The download link is called:
Quote: |
Sample Source Code July 2010
|
You can translate it to CCS.
1. Get rid of all the UART setup code which talks to PIC registers and just
put in the usual #use rs232() statement above main().
2. Get rid of the 7-segment code. You don't need it. Display the result
on an LCD, or on a RS-232 terminal window on a PC. (By using a different
RS-232 stream on different PIC pins).
3.The uart_send() function is the same as the CCS putc() function.
I think there is sample code for this type of RF link in the forum archives
(maybe for a different brand. Maybe Sparkfun ?) but I don't have time
to search for it now. |
|
|
chin0609
Joined: 13 Sep 2011 Posts: 18
|
|
Posted: Sat Oct 01, 2011 7:04 pm |
|
|
I really don't understand and have no idea how to translate the code to ccs after i see it. I am not familiar on both.
Can someone volunteer to translate sample code for me? I no need 7 segment. I just need pin high and low only. When pin high LED turn on. Just that. Appreciate.
Here the code provide in Hi-tech
transmiter:
Code: |
//===================================================================================
// include
//===================================================================================
#include <pic.h>
//===================================================================================
// configuration
//===================================================================================
__CONFIG (0x3F32);
//===================================================================================
// define
//===================================================================================
#define inc_button RA1
#define dec_button RA2
#define send_button RA3
#define display PORTB
#define SYNC_DATA 0x00
#define HEADER 0xaa
//===================================================================================
// function prototype
//===================================================================================
void uart_send(unsigned char data);
void send_packet(unsigned char data);
// main function
//===================================================================================
void main(void)
{
//assign variable
unsigned char num,no;
//7 segment display
unsigned char _7seg[16]={0b01111111,0b00001101,0b10110111,0b10011111, //0,1,2,3
0b11001101,0b11011011,0b11111011,0b00001111, //4,5,6,7
0b11111111,0b11011111,0b11101111,0b11111001, //8,9,A,B
0b01110011,0b10111101,0b11110011,0b11100011}; //C,D,E,F
ADCON1= 0x06; //configure PortA as digital I/O
TRISA = 0b111111; //configure PORTA input
TRISB = 0b00000000; //configure PORTB as output
//setup USART
BRGH = 0; //baud rate low speed option
SPBRG = 255; //set boud rate to 1200bps for 20Mhz crystal
TX9 = 0; //8-bit transmission
TXEN = 1; //enable transmission
SYNC = 0; //asynchronous
SPEN = 1; //enable serial port
num=0;
no=0;
display=_7seg[num];
while(1) //infinity loop
{
if(inc_button==0) //increase number per press
{
if(num==15) num=0; //back to 0 after F
else num+=1; //one increment
display=_7seg[num]; //display number on 7 segment
while(inc_button==0); //wait until the button is released
}
else if(dec_button==0) //decrease number per press
{
if(num==0) num=15; //go to F after 0
else num-=1; //one decrement
display=_7seg[num]; //display number on 7 segment
while(dec_button==0); //wait until the button is released
}
else if(send_button==0) //send the desired number
{
no=num;
while(send_button==0); //wait until the button is released
}
send_packet(no); //continuous send data
}
}
//===================================================================================
// functions
//===================================================================================
void uart_send(unsigned char data)
{
while(TXIF==0); //only send the new data after
TXREG=data; //the previous data finish sent
}
void send_packet(unsigned char data)
{
unsigned char i;
// Buffer for the data in one packet.
unsigned char buffer[3];
// Byte 0 is the header.
buffer[0] = HEADER;
// Byte 1 is the data.
buffer[1] = data;
// Byte 2 is the checksum.
buffer[2] = (unsigned char)(HEADER + data);
// Clocking for a while before sending the data so that the Tx and Rx are in sync.
for (i = 0; i < 7; i++) uart_send(SYNC_DATA);
// Transmit the packet using UART.
for (i = 0; i < 3; i++) uart_send(buffer[i]);
} |
Receiver:
Code: |
// include
//===========================================================================
#include <pic.h>
//===========================================================================
// configuration
//============================================================================
__CONFIG (0x3F32);
//============================================================================
// define
//============================================================================
#define display PORTB
#define HEADER 0xaa
//=============================================================================
// function prototype
//=============================================================================
unsigned char uart_rec(void);
unsigned char read_packet(void);
//============================================================================
// main function
//============================================================================
void main(void)
{
//assign variable
unsigned char num,no;
// 7 segment display
unsigned char _7seg[16]={0b01111111,0b00001101,0b10110111,0b10011111, //0,1,2,3
0b11001101,0b11011011,0b11111011,0b00001111, //4,5,6,7
0b11111111,0b11011111,0b11101111,0b11111001, //8,9,A,B
0b01110011,0b10111101,0b11110011,0b11100011}; //C,D,E,F
//set I/O input output
TRISB = 0b00000000; //configure PORTB as output
//setup USART
BRGH = 0; //baud rate low speed option
SPBRG = 255; //set boud rate to 1200bps for 20Mhz crystal
SPEN = 1; //enable serial port
RX9 = 0; //8-bit reception
CREN = 1; //enable reception
num=0;
display=_7seg[num];
while(1) //infinity loop
{
CREN=1; //enable continuos receive
if(OERR==0) no=read_packet(); //receive sata if overrun error free
else CREN=0; //if overrun error, disable continuos receive
if(no <= 0x0f) num=no; //only accept the value from 0 to f
display=_7seg[num];
}
}
//==================================================================================
// functions
//===================================================================================
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(RCIF==0); //wait for data
rec_data = RCREG;
return rec_data; //return the received data
}
unsigned char read_packet(void)
{
// Buffer for received byte.
unsigned char received_byte;
// Counter to indicate the current position of the received data packet.
static unsigned char counter = 0;
// Buffers for the data and checksum.
unsigned char data;
unsigned char checksum;
// We loop until the checksum is correct.
do {
// We will ignore the sync data and assume the header byte is the start of packet.
// Keep reading until the header byte is received.
while (uart_rec() != HEADER);
// The following byte shoulde be the data byte.
data = uart_rec();
// Then the last byte is the checksum.
checksum = uart_rec();
} while (checksum != (unsigned char)(HEADER + data));
// If the checksum is correct, return the data.
return data;
} |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sat Oct 01, 2011 7:34 pm |
|
|
Unless someone has a LOT of time of their hands AND those modules ,it is unlikely that anyone can help.I do have the time, but do not have the hardware.
The best solution is for you to take the time and experiment with PICs and C. There are lots of C books available and even CCS kindly supplies reasonably documented working examples of their code.
No one just 'gave me' working code when I started out.Had to read,read, self teach,read some more, burn my fingers soldering,etc. to LEARN how to cut Z80 assembler, Microsoft BASIC,COSMAC1802 assembler, PDP-8,PDP-11 assembler,8051 assembler, 8052 basic,FORTRAN,FORTH,C++,8088 assembler, probably anoth 10 or 12 languages as well as PIC assembler and CCS C. The latter I now do as a hobby,something to keep the brain operational.
The 'Internet' is an extremely powerful tool that you should use,make Google your best friend.You should put in at least 4 hours everyday for 10 or 12 years programming PICs. THEN and only then will you appreciate and comprehend what marvellous technology they are.
I understand that English is not everyone's first language but start small(aka 'Hello World') and learn by doing it yourself. CCS C is very powerful and I know you will learn more and understand far better if you do it yourself !
That being said , if someone wants a 'cross-compiler' cut, I'd be happy to do so for an appropriate fee,winter's coming...brrr..... |
|
|
chin0609
Joined: 13 Sep 2011 Posts: 18
|
|
Posted: Sat Oct 01, 2011 9:01 pm |
|
|
ok i can keep tried but i don't have a lot of time..because it regarding my final year project ..
btw can provide any useful link to study the ccs programming?
etc: ebook, sample code.. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Oct 02, 2011 6:02 am |
|
|
Here we go again..
hmm.. FINAL year project.
...so you've been in school for 2..3..4 years and now decide to 'learn' PICs and program in C ,with ,what less than 6 months before graduation ??
Guess they don't teach 'time management' in FIRST year . Too bad, because you only have 2 options. One, steal code from someone else or 'burn the midnight oil' every night and teach yourself. While the last option is the best(especially with the vast resources of the Internet) because you would acually LEARN about PICs and CCS C, you'll probably do number one and cheat,never to learn what PICs are and what they can do.On the surface you'll have to contend with power supply issues, RF
design and layout,hardware construction errors,sloppy code,PC software problems,fried components,grounding issues,EMI,plus the 'what now factor' or you could get really,really lucky and it all works the first time for you.
The program requires less than one page of code,is not hard or complicated and requires about 5 easy evening's work.
Night one,construct 2 test boards and test with 'blink LED' programs.
Night two,cut code to send data from one board to the other.easy night!
Night three,cut code to use the RF tx/rx modules,test with night 2 code.
Night four, debug WHY code/modules failed last night .Not so easy.
Night five,confirm final code works,printout report and code to hand in.
Done, finished, end of report.
-30- |
|
|
chin0609
Joined: 13 Sep 2011 Posts: 18
|
|
Posted: Sun Oct 02, 2011 6:37 am |
|
|
temtronic can translate the code for me? just try pls.. just translate from the High tech code to ccs code...
so i can test it in my program..
thanks. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Oct 02, 2011 7:46 am |
|
|
Code is easy to translate, took me less then 1 hour with 2 coffee breaks.
Sorry but unable to test as I do not have those modules and will send you my version of that code as I do not give code that I have not tested 100%. You should be able to accomplish it in less than a day or two, maybe 12-14 hours of real benchwork.
BTW the last 'final project' I did was in 1974 when I received my Honours in Avionics. Things sure have changed since then ! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Oct 02, 2011 10:48 am |
|
|
temtronic wrote: | Here we go again..
hmm.. FINAL year project.
...so you've been in school for 2..3..4 years and now decide to 'learn' PICs and program in C ,with ,what less than 6 months before graduation ??
|
yea.. I work for a top10 engineering university and I can tell you it's not any better. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Oct 02, 2011 12:36 pm |
|
|
Beyond the FCC problem with incorporating these particular "links".
Did I forget to mention that there is no useful
DC restoration on these links either??
If this pair of TX/RX modules was intended as an actual component of a real world, aimed at commercial - design - all that awaits the adopter is trouble -
all politely - IMHO that is |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Oct 02, 2011 2:46 pm |
|
|
get yourself the book "The C Programming Language" by Kergnihan & Ritchie.
It's the definitive reference on 'C'.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|