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.

UART mikroC 16F877a interfacing

Status
Not open for further replies.

varunme

Advanced Member level 3
Advanced Member level 3
Joined
Aug 10, 2011
Messages
741
Helped
17
Reputation
36
Reaction score
17
Trophy points
1,318
Activity points
5,765
in the below code , it is to display "start" as soon as the com port / uC is connected isnt it ?, but it isnt and whenever the UART1_Write_Text is used, then some problem is there, but the program is echoing the character i sent

compiler mikroC and using hyperterminal

Code:
char uart_rd;

void main() {
  ADCON1 |= 0x0F;                 // Configure AN pins as digital
  CMCON  |= 7;                    // Disable comparators
  
  UART1_Init(19200);               // Initialize UART1 module at 9600 bps
  Delay_ms(100);                  // Wait for UART 1module to stabilize
  UART1_Write_Text("Start");
  UART1_Write(13);
  UART1_Write(10);
  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {     // If data is received,
      uart_rd = UART1_Read();     //   read the received data,
      UART1_Write(uart_rd);       //   and send data via UART1
    }
  }
}
 

The recommend/available BAUD rate depends largely on Fosc or crystal frequency.

What is your Fosc/Crystal frequency and have you set the frequency in the MikroC IDE?

In selecting the BAUD rate you must attempt to keep the %Error between the Desired and Obtainable BAUD Rates as close to zero as possible.

These %Error rates can be calculated by hand or obtain in the PIC16F87XA Datasheet, Table: 10-3 and 10-4:



%Error over 1% are increasingly prone to transmission/receiving problems.

BigDog
 
  • Like
Reactions: varunme

    varunme

    Points: 2
    Helpful Answer Positive Rating
UART1_Init(19200);
Means that you are using 19200 Baud Rate

UART1_Write_Text("Start");
//Means you are sending the "Start" to the Serial Pins of the Controller

UART1_Write(13);
//Means you are using Carriage return in short "ENTER" key of keyboard whose ASCII value is 13

UART1_Write(10);
//Means you are using Line Feed whose ASCII value is 10
//Search Google to see the difference b/w Line Feed and Carriage Return


if (UART1_Data_Ready()
//The above Statement check whether u are receiving any data from the serial pins or not
//If you are getting some data then following commands will get executed

uart_rd = UART1_Read(); // read the received data,
//Whatever character u received is stored in the uart_rd variable

UART1_Write(uart_rd); // and send data via UART1
//And What ever variable you read is sent to the Serial PORT Again

Open Hyper-Terminal in Windows
Connect the Controller with appropriate logic conversion(MAX232) with the serial port of computer
then POWER-ON the Controller

You will get a "Start" on the hyperterminal 'don't forget to set the baud rate of PC's Hyper-Termianl
after that
whatever you type on the Hyper-Terminal you will be able to see that..


Hope this explanation helps u


Regards
Arun Sharma
 
UART1_Init(19200);
Means that you are using 19200 Baud Rate

UART1_Write_Text("Start");
//Means you are sending the "Start" to the Serial Pins of the Controller

UART1_Write(13);
//Means you are using Carriage return in short "ENTER" key of keyboard whose ASCII value is 13

UART1_Write(10);
//Means you are using Line Feed whose ASCII value is 10
//Search Google to see the difference b/w Line Feed and Carriage Return


if (UART1_Data_Ready()
//The above Statement check whether u are receiving any data from the serial pins or not
//If you are getting some data then following commands will get executed

uart_rd = UART1_Read(); // read the received data,
//Whatever character u received is stored in the uart_rd variable

UART1_Write(uart_rd); // and send data via UART1
//And What ever variable you read is sent to the Serial PORT Again

Open Hyper-Terminal in Windows
Connect the Controller with appropriate logic conversion(MAX232) with the serial port of computer
then POWER-ON the Controller

You will get a "Start" on the hyperterminal 'don't forget to set the baud rate of PC's Hyper-Termianl
after that
whatever you type on the Hyper-Terminal you will be able to see that..


Hope this explanation helps u


Regards
Arun Sharma

whenever the UART1_Write_Text is used, then some problem is there, but the program is echoing the character i sent

The usage of UART1_Write_Text is the problem, not getting the start message and whenever i use UART1_Write_Text , some problem in sending
 

First open Hyper-Terminal

Then Select Baud Rate
and after that
Power-ON your Micro-Controller board..
.

Few months back...
When i have started using pic
i am using mikroC compiler and at that time i had just copy paste that code available in help documentation of mikroc
Which is exactly your ones..

means u to have copy the code from help documentation

for me it works..

so the problem is from ur end not from compiler end
 
yess......

Thumbs-up-icon.png
 
I prefer PuTTY over Hyperterminal.

PuTTY Download Page

I find it a lot more versatile and supports many more features including SSH

The newline or return characters maybe cause some issue:

Try

Code:
 UART1_Write_Text("Start\n\r");

Or

Code:
 UART1_Write_Text("Start\n");


Instead Of:


Code:
 UART1_Write_Text("Start");
 UART1_Write(13);
 UART1_Write(10);

BigDog
 

in serial communication with C#, will these produce problems ?

---------- Post added at 10:11 ---------- Previous post was at 10:09 ----------

I prefer PuTTY over Hyperterminal.

PuTTY Download Page

I find it a lot more versatile and supports many more features including SSH

The newline or return characters maybe cause some issue:

Try

Code:
 UART1_Write_Text("Start\n\r");

Or

Code:
 UART1_Write_Text("Start\n");


Instead Of:


Code:
 UART1_Write_Text("Start");
 UART1_Write(13);
 UART1_Write(10);

BigDog

After the starting point

Code:
 UART1_Write_Text("Start\n");

 UART1_Write_Text("Start\n\r");

may solve the UART1_Write_Text issue ?
 

in serial communication with C#, will these produce problems ?

No if you use everything properly then no problem will occur...

Have u solved ur problem..
It working now... or not..
 
yes its working,
Thanks dear,
 

    V

    Points: 2
    Helpful Answer Positive Rating
And Download Putty...
as BigDogGuru Suggested..

It much better than Hyper-Terminal of Windows
And One thing more
You may not find Hyper-Terminal in windows 7
in that case use putty

---------- Post added at 22:49 ---------- Previous post was at 22:47 ----------

yes its working,
Thanks dear,

:)
Your Welcome
 
yes,
i use winXP in laptop for embedded
and desktop win7, but hyperterminal can be ported to win7 also,

But i will download putty today, to lessen by headache, thanks for you both.
 

can we use something like the below in mikroC ?

Code:
char uart_rd;

void main() {
  ADCON1 |= 0x0F;                 // Configure AN pins as digital
  CMCON  |= 7;                    // Disable comparators

  UART1_Init(9600);               // Initialize UART1 module at 9600 bps
  Delay_ms(100);                  // Wait for UART 1module to stabilize
  UART1_Write_Text("Start");
  UART1_Write(13);
  UART1_Write(10);
  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {  
    uart_rd = UART1_Read(); //   read the received data,
    switch (uart_rd )       // If data is received,
    {
     case 1:
     portb.f1=1;
     case 2:
      portb.f2=1;
     
    
    }

     // UART1_Write(uart_rd);       //   and send data via UART1
    }
  }
}
 

can we use something like the below in mikroC ?

Code:

char uart_rd;

void main() {
ADCON1 |= 0x0F; // Configure AN pins as digital
CMCON |= 7; // Disable comparators

UART1_Init(9600); // Initialize UART1 module at 9600 bps
Delay_ms(100); // Wait for UART 1module to stabilize
UART1_Write_Text("Start");
UART1_Write(13);
UART1_Write(10);
while (1) { // Endless loop
if (UART1_Data_Ready()) {
uart_rd = UART1_Read(); // read the received data,
switch (uart_rd ) // If data is received,
{
case 1:
portb.f1=1;
case 2:
portb.f2=1;


}

// UART1_Write(uart_rd); // and send data via UART1
}
}
}


Yes we can,
But what is this PORTB.F1

I don't understand this..
 
first bit of portb
 

Yes it will work..
But Make sure that uart_rd is a single byte character..
 
But itsnt working , this is my final code

Code:
char uart_rd;

void main() {
trisb=0;
portb=0;
  ADCON1 |= 0x0F;                 // Configure AN pins as digital
  CMCON  |= 7;                    // Disable comparators

  UART1_Init(9600);               // Initialize UART1 module at 9600 bps
  Delay_ms(100);                  // Wait for UART 1module to stabilize
  UART1_Write_Text("Start");
  UART1_Write(13);
  UART1_Write(10);
  while (1) {                     // Endless loop
    if (UART1_Data_Ready()) {  
    uart_rd = UART1_Read(); //   read the received data,
    switch (uart_rd )       // If data is received,
    {
     case 1:
     portb.f1=1;
     delay_ms(500);
     case 2:
      portb.f2=1;
      delay_ms(500);
     
    
    }

     // UART1_Write(uart_rd);       //   and send data via UART1
    }
  }
}
 

WIll be Describe what happens....


If you Press 1 in Hyperterminal, then your first Case statement will gets executed..
and The first pin of PORTB gets high

I am not much aware with the Mikro C sytax..

But there must be a break after every case
Code:
case 1:
     portb.f1=1;
     delay_ms(500);
      break;
     case 2:
      portb.f2=1;
      delay_ms(500);
      break;

Hope this Helps
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top