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.

source code (mikro-c compiler) of RF wireless data transmission

Status
Not open for further replies.

pigbaobao

Member level 2
Member level 2
Joined
Oct 16, 2010
Messages
42
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,707
Hi, I am proceeding a project which is a wireless data transmission using RF module. :)

I was done a source code (Mikro-c compiler) and i dun know where the problem is. 8O

I am newbie in c-programming and i sincerely ask from you all suggestion or any idea about my project. :|

Below is my simple source code for transmission side and receiver side. Any pro please help me check whether the program is correct or where need to edit. Thank for help, i very appreciate it...^^ :lol: :p

Transmission side,

#include <stdio.h>

#define click_button RA1
#define send_button RA2

char string;

void main() {

unsigned int num;
char string1[]= "Welcome";
char string2[]= "Final Year Project";
char string3[]= "Wireless Data Transmission";
char string4[]= "Thank You";

ANCON1 = 0; // Configure AN pins as digital


TRISA = 0b11111111; //configure PORTA as input
TRISB = 0b00000000; //configure PORTB as output
PORTC = 1; //LED ON
TRISC = 1;
Delay_ms(1000);

UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize

num=0;

while(click_button == 1)
{
num++;
if(num > 3)
num=0;
Delay_ms(1000);
}


while(send_button == 1)
{
UART1_Write(string[num]);
Delay_ms(1000);
}

}



Receiver side,

#include <stdio.h>


// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;

sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections

char string[];

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

void main(){

PORTC = 1; //LED
TRISC = 1;
TRISD = 0;
PORTD = 0xFF;
TRISD = 0xff;
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

UART1_Init(9600);
while (UART1_Data_Ready() == 1) {

string = UART1_Read();

Lcd_Out(1,6,string); // Write text in first row
Lcd_Out(2,6,string); // Write text in second row
Delay_ms(8000);
Lcd_Cmd(_LCD_CLEAR); // Clear display



// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}

while(1) { // Endless loop
for(i=0; i<8; i++) { // Move text to the left 7 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}

for(i=0; i<8; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}
}
 

Sir,


Lcd_Out(1,6,string); // Write text in first row
Lcd_Out(2,6,string); // Write text in second row

please check above two commands "string"

Build the program
if it shbows any error publish here
 
Hi Friend, below is the error appear after i had build the program.


Line MessageNo File Name
0 1 mikroCPIC1618.exe -MSF -DBG -pP16F877A -DL -O11111114 -fo20 -N"C:\Users\Pig\Desktop\Test1rx\Testrx.mcppi" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P16\" -SP"C:\Users\Pig\Desktop\Test1rx\" -SP"C:\Users\Pig\Desktop\Test1\" "Testrx.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM.mcl" "__Lib_FLASH_RW.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl"
warning: 0 1501 Specified search path does not exist: 'C:\Users\Pig\Desktop\Test1'
hint: 0 1138 Available RAM: 352 [bytes], Available ROM: 8192 [bytes]
diagnostics: 0 126 All files Preprocessed in 172 ms
diagnostics: 0 122 Compilation Started Testrx.c
error: 31 324 Undeclared identifier 'ANCON1' in expression Testrx.c
warning: 39 1509 Generated baud rate is 9615 bps (error = 0.16 percent) Testrx.c
error: 42 318 Assigning to non-lvalue '' Testrx.c
error: 0 102 Finished (with errors): 19 Oct 2010, 01:10:07 Testrx.mcppi


Thanks for ur help. ^^

---------- Post added at 01:15 ---------- Previous post was at 01:12 ----------

Note : I have change the ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;

to ADCON1 = 0

---------- Post added at 01:15 ---------- Previous post was at 01:15 ----------

Note : I have change the ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;

to ADCON1 = 0
 

Dear friend,

Did you build the same project?

error: 31 324 Undeclared identifier 'ANCON1' in expression Testrx.c

ANCON1(correct form ADCON1) here such a type register not used in your program.So please check project name

post your replay
 
Hi friend, after i re-correct the program, the error for ADCON1 has been solved. But still got a minor error between the string, can u give me some idea or suggestion how to solve this problem? Below is the error....

Line MessageNo File Name
0 1 mikroCPIC1618.exe -MSF -DBG -pP16F877A -DL -O11111114 -fo20 -N"C:\Users\Pig\Desktop\Test1rx\Testrx.mcppi" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\defs\" -SP"C:\Program Files\Mikroelektronika\mikroC PRO for PIC\Uses\P16\" -SP"C:\Users\Pig\Desktop\Test1rx\" -SP"C:\Users\Pig\Desktop\Test1\" "Testrx.c" "__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl" "__Lib_CMath.mcl" "__Lib_Conversions.mcl" "__Lib_Sprinti.mcl" "__Lib_Sprintl.mcl" "__Lib_Time.mcl" "__Lib_Trigonometry.mcl" "__Lib_Button.mcl" "__Lib_Keypad4x4.mcl" "__Lib_Manchester.mcl" "__Lib_OneWire.mcl" "__Lib_PS2.mcl" "__Lib_Sound.mcl" "__Lib_SoftI2C.mcl" "__Lib_SoftSPI.mcl" "__Lib_SoftUART.mcl" "__Lib_ADC_A_C.mcl" "__Lib_EEPROM.mcl" "__Lib_FLASH_RW.mcl" "__Lib_I2C_c34.mcl" "__Lib_PWM_c21.mcl" "__Lib_SPI_c345.mcl" "__Lib_UART_c67.mcl" "__Lib_PortExpander.mcl" "__Lib_CANSPI.mcl" "__Lib_CF.mcl" "__Lib_GlcdFonts.mcl" "__Lib_Glcd.mcl" "__Lib_LcdConsts.mcl" "__Lib_Lcd.mcl" "__Lib_RS485.mcl" "__Lib_T6963C.mcl" "__Lib_SPIGlcd.mcl" "__Lib_SPILcd.mcl" "__Lib_SPILcd8.mcl" "__Lib_SPIT6963C.mcl" "__Lib_EthEnc28j60.mcl"
warning: 0 1501 Specified search path does not exist: 'C:\Users\Pig\Desktop\Test1'
hint: 0 1138 Available RAM: 352 [bytes], Available ROM: 8192 [bytes]
diagnostics: 0 126 All files Preprocessed in 250 ms
diagnostics: 0 122 Compilation Started Testrx.c
warning: 40 1509 Generated baud rate is 9615 bps (error = 0.16 percent) Testrx.c
error: 43 318 Assigning to non-lvalue '' Testrx.c
error: 0 102 Finished (with errors): 19 Oct 2010, 13:20:46 Testrx.mcppi


Hope you can help~ Thank anyway! ^^
 

Dear friend,

if error occurred in rxr side then use this program

char string[45];

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

void main()
{
int i=0;
PORTC = 1; //LED
TRISC = 1;
TRISD = 0;
PORTD = 0xFF;
TRISD = 0xff;
trisa=0x00;

Lcd8_Init(&portb,&portd);; // Initialize LCD

Lcd8_Cmd(LCD_CLEAR); // Clear display
Lcd8_Cmd(LCD_CURSOR_OFF); // Cursor off

Usart_Init(9600);
while (Usart_Data_Ready() == 1) {

string = Usart_Read();
i++;
Lcd8_out(1,6,string); // Write text in first row
Lcd8_Out(2,6,string); // Write text in second row
Delay_ms(8000);
Lcd_Cmd(LCD_CLEAR); // Clear display



// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(LCD_SHIFT_RIGHT);
Move_Delay();
}

while(1) { // Endless loop
for(i=0; i<8; i++) { // Move text to the left 7 times
Lcd_Cmd(LCD_SHIFT_LEFT);
Move_Delay();
}

for(i=0; i<8; i++) { // Move text to the right 7 times
Lcd_Cmd(LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}
}
/*
no need for #include <stdio.h>

just copy paste this program.
 
Hi friend, Thanks for your help! It is work!^^

Can i ask a question about the " char string[45]; ", can u briefly explain to me the [45] means to?
 

Dear friend,

char string[45]; this means array size is 45.Actually you can change array size depending on your program.
string = Usart_Read(); Here up to 45 characters you can store in your array.
 
Thx fren...can u help me again?
Now i am doing simulation about this project...now i am try to mix the transmitter program to receiver program into 1 single program for further simulation...Can u give me suggestion or simple example based on above program?Let say we temporary put the wireless program aside, and doing a one simple individual program for a digital input (button) send a digital output (active high or low) to LCD.

It is about 1 increment button and another 1 is send button....after click for a number times of increment button, the send button will be pressed and the digital output "0" (active low) will be sent to the LCD through PIC...and the LCD will show difference character depend on how many times we pressed in increment button....there are 4 group of character word such as "welcome", "FYP project","Wireless data transmission", and "thank you" to be shown at LCD....

Hope u can help me again....thx anyway....^^
 

Dear friend,

I think you mean software simulation,

here i post program for serial read and write display it on lcd.

void main()
{
char k;
Usart_Init(9600);
Lcd_Init(&portb);
Lcd_Cmd(lcd_cursor_off);
Lcd_Cmd(lcd_clear);
while(1)
{
while(!Usart_Data_Ready());
{
k=Usart_Read();
Usart_Write(k);
Lcd_Chr(1,1,k);
}
}
}
 
Hi friend,

Actually i am not intend to use UART in this program...It is because i have been informed that my program just using a digital input (button) and send signal via PIC to LCD for show the character (am i right? or...)...And the character word depend on how many time i was click on that button...

I am trying to construct a simulation circuit in Proteus Professional to test my program...unfortunately when i click the increment button and send button, there is no output in my LCD display. Here is my simulation program, although it can be build successfully...


// LCD module connections
sbit LCD_RS at RD4_bit;
sbit LCD_EN at RD5_bit;
sbit LCD_D4 at RD0_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D7 at RD3_bit;

sbit LCD_RS_Direction at TRISD4_bit;
sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D4_Direction at TRISD0_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D7_Direction at TRISD3_bit;
// End LCD module connections

#define click_button RA1
#define send_button RA2

unsigned int num;
char string1[]= "Welcome";
char string2[]= "Final Year Project";
char string3[]= "Wireless Data Transmission";
char string4[]= "Thank You";


char *string;

void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}

void main() {

int i=0;
TRISA = 0xFF; //configure PORTA as input
TRISB = 0x00; //configure PORTB as output
PORTC = 0; //LED
TRISC = 0;
TRISD = 0;
PORTD = 0x00;
TRISD = 0x00;


Lcd_Init();; // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,3,"Wireless Data");
Lcd_Out(2,4,"Transmission");
Delay_ms(6000);
Lcd_Cmd(_LCD_CLEAR); // Clear display

Uart1_Init(9600);
num=0;

if(click_button == 0)
{
num++;
if(num > 3)
num=0;
Delay_ms(1000);
}
if(send_button == 0)
{
UART1_Write(string[num]);
Delay_ms(1000);
}


Lcd_out(1,6,string); // Write text in first row
Lcd_out(2,6,string); // Write text in second row
Delay_ms(8000);
Lcd_Cmd(_LCD_CLEAR); // Clear display



// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}

while(1) { // Endless loop
for(i=0; i<8; i++) { // Move text to the left 7 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}

for(i=0; i<8; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
}
}


Hope u all can found out what is the problem and give me some ideas...thank =]
 

Dear friend,

Use this program

Make portb as input and connect switch in pb0 th pin.

char string1[]= "Welcome";
char string2[]= "Final Year Project";
char string3[]= "Wireless Data Transmission";
char string4[]= "Thank You";
void main()
{
int i=0;
trisb=0xf0;
Lcd8_Config(&portc,&portd,4,6,5,7,6,5,4,3,2,1,0);
Delay_ms(100);
while(1)
{
if((portb.f0==1)&&(i==0))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string1);
i++;
}
if((portb.f0==1)&&(i==1))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string2);
i++;
}
if((portb.f0==1)&&(i==2))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string3);
i++;
}
if((portb.f0==1)&&(i==3))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string4);
i=0;
}
}
}
 
Dear friend, it is work and successful running in LCD.Thanks...

But i still have question to ask, when i trying to show the character with two rung in the LCD, it cannot work correctly.

For an example,
char string1[]= "Welcome";
char string2[]= "Final Year";
char string3[]= "Project";
char string4[]= "Wireless Data";
char string5[]= "Transmission";
char string6[]= "Thank You";


while(1)
{
if((portb.f0==1)&&(i==0))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string1);
i++;
}
if((portb.f0==1)&&(i==1))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string2);
Lcd8_Out(2,1,string3);
i++;
}
if((portb.f0==1)&&(i==2))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string4);
Lcd8_Out(2,1,string5);
i++;
}
if((portb.f0==1)&&(i==3))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string6);
i=0;
}
}

This is the program i intend to do, but it cannot show it in LCD, and i don't know what is the problem. Furthermore, i am also try to make the charater to move right or left for each string[] in LCD but failed, i think probably my program not good enough or wrong, so hope u can help me again. Thanks friend...^^
 

Dear friend,

The program is correct,then pleas check your hardware connection



char *string1= "Welcome";
char *string2= "Final Year Project";
char *string3= "Wireless Data Transmission";
char *string4= "Thank You";
char str2[]="hello";
void main()
{
int i=0;
trisb=0x0f;
Lcd8_Config(&portc,&portd,4,6,5,7,6,5,4,3,2,1,0);
//Delay_ms(100);
Lcd8_Out(1,1,str2);
while(1)
{
if((portb.f0==1)&&(i==0))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string1);
i++;
}
if((portb.f0==1)&&(i==1))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string2);
i++;
}
if((portb.f0==1)&&(i==2))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string3);
i++;
}
if((portb.f0==1)&&(i==3))
{
Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string4);
i=0;
}
}
}
 

Hi friend,
Yup, yours program is correct and i simulate successfully. Since my LCD is 16x2, so my character more than my LCD if just put it ...an example,

Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string3);

so i intend to do it like this...(an example),

Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string3);
Lcd8_Out(2,1,string4);

but it is not work. ==''

Friend, I am try to change the program porta as input...

trisb=0xf0 to trisa=0xf0 and
portb.f0 to porta.f0

but cannot work correctly...can u tell me what is the problem caused this happened?
 

Dear friend,

Split the sentence like

char *string3= "Wireless Data Transmission";

split it

char *string3="wireless data";
char *string 4="Transmission";


then use this commands


Lcd8_Cmd(lcd_clear);
Lcd8_Out(1,1,string3);
Lcd8_Out(2,1,string4);

For Porta ,properly configure ADCON register.
 
Hi friend,

thanks for your reply. Can u explain to me why just porta we need to configure ADCON register whereas portb no need?

If i configure,
ADCON1=0x06;
trisa=0b111111;

What should i put in this function?

if((*******==1)&&(i==0))


Thanks for help...

---------- Post added at 17:33 ---------- Previous post was at 17:21 ----------

Hi friend,
Thanks your patient keep reply my question, i really appreciate it!

I do it before split the sentence in my program, but the output in LCD either show welcome and wireless data transmission or final year project and thank you only, it will not comes out in 4 actual sequences.

So i just wonder why happened like this...
 

Dear friend,

porta has dual function

1. It is used for A/D conversion
2. I/O purpose

That is here ADCON1=0x06; it means that porta has used for i/o purpose.For more details pleas refer your pic data sheet.

Here porta.f0 is used for read your switch,so check whether the pin has one or not.If it is one ,means key is pressed .
So, you use

if((porta.f0=1)&&(i==0))
 
Thanks friend,

Sorry for give the wrong detail of question, in PIC16F877A portA only has 6 pin, so i shouldn't define it as 0xf0. So let say if i intend to make portA as input 0x3f (since it only have 6 pin, or 0b111111), but when i configure the function as if((porta.3f=1)&&(i==0)) and it cannot be build since the "3f", so what should i do?


I have solve the second question....thanks anyway!^^
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top