Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC16F877 and serial input

Status
Not open for further replies.

saadia47

New Member
Hi,
I have setup the hardware with PIC16F877 which is deriving a display screen. I have written initialisation codes. I am using EasyPIC5 board and the MicroC program to download my C codes in the PIC16F877. This works perfectly.
Now, I have made serial connections (RS232) from a microprocessor to this PIC16F877, and I want to send instructions saying initialise the display(above) to the PIC from this microprocessor. These instructions should be sent via the RS232. I want to understand how does the PIC understand my instruction and do this? How do I setup this command in serial input stream? and write this command from the microprocessor and PIC recognise it as initialising the display?
If anyone can give me some idea or perhaps anyone has done this already could help me on this. I will appreciate it.
Thanks alot.
 
Now, I have made serial connections (RS232) from a microprocessor to this PIC16F877, and I want to send instructions saying initialise the display(above) to the PIC from this microprocessor. These instructions should be sent via the RS232. I want to understand how does the PIC understand my instruction and do this?

The PIC doesn't understand anything, you have to implement a protocol and write software at both ends to make it act as you want. Essentially the PIC and LCD is acting as a terminal, and you might have a look at ACSII and the control codes that uses.
 
Ok, what type of protocol.And how do I write it?

Whatever you want to make it, like I said basing it on ASCII would seem a good idea. You might try checking what commercially available serial LCD's use.

Basically you're looking at control codes, these are the low numbers in ASCII, and need to be checked for and processed accordingly.

Do I have to use interupts in this case?
Thanks

Only if you want to, as it's presumably doing little else than waiting for serial data and tranferring it, there probably isn't any great need to.
 
I understand what you mean. But I cant get to write the control codes and how to call them in case when they are supposed to be used.

Can you give me an example code for this piece..thanks
 
re:

Hi, sadia. what i understand from your question is to communicate u processor and u controller and you want to run lcd upon command from u processor
if(i understood true) then
.if you simply wants an instruction to just initialize lcd. you can use simple output pin from processor and input pin to controller.

if you need full message for lcd from processor then just communicate usarts of both. send msg from processor . take that in controller display it.
if you find difficulty let me know. it looks to simple if i understood.
.Chacha teefa
 
I understand what you mean. But I cant get to write the control codes and how to call them in case when they are supposed to be used.

Can you give me an example code for this piece..thanks

I don't have time to write code for people, but essentially they are two separate considerations - commands and data.

The normal operating of the device will be data - you send an 'A' and it prints an 'A', you send a 't' it prints a 't' - pretty simple.

Then there are ASCII control data, you send the ASCII symbol for CLR and it clears the screen, you send CR and it scrolls the display and places the cursor on the bottom line. Any of these control codes needs to branch to separate code sections to complete.

Then there is actual LCD commands (assuming you want to go to this level?), you would need to send a specific unused control code, and this would switch the PIC to expect command codes rather than data, and the PIC would switch the LCD to command mode and pass the following data to it. Another control code (or the same one again) could be used to switch the PIC back to normal operation.
 
I don't have time to write code for people, but essentially they are two separate considerations - commands and data.

The normal operating of the device will be data - you send an 'A' and it prints an 'A', you send a 't' it prints a 't' - pretty simple.

Then there are ASCII control data, you send the ASCII symbol for CLR and it clears the screen, you send CR and it scrolls the display and places the cursor on the bottom line. Any of these control codes needs to branch to separate code sections to complete.

Then there is actual LCD commands (assuming you want to go to this level?), you would need to send a specific unused control code, and this would switch the PIC to expect command codes rather than data, and the PIC would switch the LCD to command mode and pass the following data to it. Another control code (or the same one again) could be used to switch the PIC back to normal operation.

I understand that you're very busy. Sorry If I asked you.
OK, I already have the code to initialise the display screen. I just want to call up the initialisation when the ON command for example is send from the u processor to the PIC via RS232. I want to understand that how can I tell the PIC to use this piece of initialisation (and initilise the display) when a 'ON' command or signal is sent from the micrprocessor.
I dont want to write any characters on the display at the moment.
I hope now that you understand what I am looking for.

Thanks alot
 
In rough (no particular language)

If ReceivedCharacter = 'ON' then Goto PerformInitialisation
Else Goto SomethingElse

But why would you want to be initialising the LCD over the serial interface, the PIC should do that itself as part of it's setup procedure.
 
I am just an intern student. I am doing internship at a displays company.
They want the microprocessor to control PIC which is already used to initialise the display. So I am given this task to do so...believe me I am also not provided with any help at all about this project. Anyways I still have to do it..so thats why I am looking for help in forums.
I guess they want to use this microprocesser to control several PICs with the displays attached later on industrial applications.

I am sorry if I am a pain...:(
But thanks for the support
 
Please see the attached document which describes what I intend to do.
Any comments or suggestions are welcome.
 

Attachments

  • outline for the project2.pdf
    29.3 KB · Views: 212
The PDF doesn't really say what you're supposed to do? - but it does say the PIC is already programmed.

Presumably there's more to the question than you posted?.
 
let me see pdf...

then i will do something dont worry...i can do this
mein kapdey doh kar ayaaa...
 
Last edited:
Code with proteus example

Mai g,
Here is a code check it if any prob let me know.You can download whole MikroC files and proteus in code.zip attachment.
#define SWITCH portb.f0
#define ON 1
#define OFF 0

char Buffer[]=" ";
unsigned char BufferCounter=0;
unsigned short i;
void init_oled(void);
void clear_buffer(void);

void main() {

char cmd1[]="ON";
char cmd2[]="OFF";

trisb=0; //to make switch as output bit
Usart_Init(2400);//you can specify your dm355's baud rate
SWITCH=0;
do {
if (Usart_Data_Ready()) { // If data is received
i = Usart_Read(); // Read the received data
Buffer[BufferCounter]=i;
if(strncmp(Buffer,cmd1,2)==0)
{
init_oled();
SWITCH=ON;
clear_buffer();
}
else if(strcmp(Buffer,cmd2)==0)
{
init_oled(); //init oled
SWITCH=OFF;
clear_buffer();
}
else
{
if(++BufferCounter> 2)BufferCounter=0;
}
}
} while (1);
}//~!

void clear_buffer(void)
{
BufferCounter=0;
Buffer[0]=' ';
Buffer[1]=' ';
Buffer[2]=' ';
}

void init_oled(void)
{
//here will be your OLED INIT code
}
 

Attachments

  • Code.zip
    28.8 KB · Views: 165
re.

You need to change Switch pin i used portb.f0.
and important thing is baudrate i remain it 2400bps but normally industry standard is 9600bps i dont know what is your processors baudrate.
 
Mai g,
Here is a code check it if any prob let me know.You can download whole MikroC files and proteus in code.zip attachment.
#define SWITCH portb.f0
#define ON 1
#define OFF 0

char Buffer[]=" ";
unsigned char BufferCounter=0;
unsigned short i;
void init_oled(void);
void clear_buffer(void);

void main() {

char cmd1[]="ON";
char cmd2[]="OFF";

trisb=0; //to make switch as output bit
Usart_Init(2400);//you can specify your dm355's baud rate
SWITCH=0;
do {
if (Usart_Data_Ready()) { // If data is received
i = Usart_Read(); // Read the received data
Buffer[BufferCounter]=i;
if(strncmp(Buffer,cmd1,2)==0)
{
init_oled();
SWITCH=ON;
clear_buffer();
}
else if(strcmp(Buffer,cmd2)==0)
{
init_oled(); //init oled
SWITCH=OFF;
clear_buffer();
}
else
{
if(++BufferCounter> 2)BufferCounter=0;
}
}
} while (1);
}//~!

void clear_buffer(void)
{
BufferCounter=0;
Buffer[0]=' ';
Buffer[1]=' ';
Buffer[2]=' ';
}

void init_oled(void)
{
//here will be your OLED INIT code
}

Thanks for the quick code. Can you explain me the code. So that I can understand its working.Cheers
 
you did a small question but its answer is huge? can you pls tell where you are facing problem?.if you like to tell me wht types of displays your company make. so, may be i can guess better about your project
 
you did a small question but its answer is huge? can you pls tell where you are facing problem?.if you like to tell me wht types of displays your company make. so, may be i can guess better about your project

Sorry, I mean can you explain the working of the code you have posted.
Cheers
 
Status
Not open for further replies.

Latest threads

Back
Top