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.

Soft Uart transmission in pic18f452

Status
Not open for further replies.

sobia sarwar

Member level 5
Member level 5
Joined
Nov 15, 2012
Messages
81
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,883
i wanted to send some data as text through soft uart to pc because i have already used my tx and rx pins.
 

you have a very vague question. we all need to know the compiler and other stuffs about your project. if you are using the mikroC compiler, there is a software UART library already included in it. refer its documentation.
 

i m using Mikroc pro V4 as compiler and proteus V7 as simulation software. i tried the example of soft uart from mikroc pro library but it dosen't work
 

i tried the example of soft uart from mikroc pro library but it dosen't work

are you saying that the MiKroC Pro library software & the example are bad pieces of software code ?

If not, then you need to give some details of what actually happens, how you put it together, what code you wrote, what settings etc etc.
 

this is not what i actually wanted to say. here is he code I tried
Code:
char i, error, byte_read;                 // Auxiliary variables

void main(){

  ANSEL  = 0;                             // Configure AN pins as digital I/O
  ANSELH = 0;
  
  TRISB = 0x00;                           // Set PORTB as output (error signalization)
  PORTB = 0;                              // No error

  error = Soft_UART_Init(&PORTC, 7, 6, 14400, 0); // Initialize Soft UART at 14400 bps
  if (error > 0) {
    PORTB = error;                        // Signalize Init error
    while(1) ;                            // Stop program
  }
  Delay_ms(100);

  for (i = 'z'; i >= 'A'; i--) {          // Send bytes from 'z' downto 'A'
    Soft_UART_Write(i);
    Delay_ms(100);
  }
   
  while(1) {                              // Endless loop
    byte_read = Soft_UART_Read(&error);   // Read byte, then test error flag
    if (error)                            // If error was detected
      PORTB = error;                      //   signal it on PORTB
    else
      Soft_UART_Write(byte_read);         // If error was not detected, return byte read
    }      
}

i wanted to know that in
Soft_UART_Init(&PORTC, 7, 6, 14400, 0);
what does &PORTC stands for means which port i have to give there.

- - - Updated - - -

actually i m using PIC18F452 AND I HAVE ALREADY USED TX AND RX PIN OF pic18f452 for serial communication now i just wanted to send some text like
your vote casted
to pc through serial comm and what i read about i have to use soft uart but i m not getting how to use soft uart
 

&PORTC means you are using PORTC for SoftUART in that 7 and 6 pins are used for SoftUART Communication. 14400 is the baudrate. Please check the SoftUART Library. Post your mikroC Project files in a zip file.
 

That line is the port on whose pins you have Rx and Tx connected. Then next 2 parameters are the pin numbers for Rx and Tx respectively

Also i believe your interrupts should be disabled.

So what actually does happen then ? At first sight your code looks OK. What have you connected this to ?
Make sure all your parameters match - Start bit/ Stop bit, Parity, inverted/ non-inverted, and of course baudrate
 

zip file including mikroc pro file and proteus simulation

- - - Updated - - -

i changed the code a little more
Code:
char error, byte_read;
int i;
char text[15]="vote casted";  
void Soft_UART_Write_Text(char *text) {
     unsigned int x = 0;
     for(x = 0; x <= strlen(text); x++) {
         Soft_UART_Write(text[x]);
     }
 }               // Auxiliary variables
void main(){

  //ANSEL  = 0;                             // Configure AN pins as digital I/O
  //ANSELH = 0;

  TRISB = 0x00;                           // Set PORTB as output (error signalization)
  PORTB = 0;                              // No error

  error = Soft_UART_Init(&PORTC, 17, 16, 9600, 0); // Initialize Soft UART at 14400 bps
  if (error > 0) {
    PORTB = error;                        // Signalize Init error
    while(1) ;                            // Stop program
  }
  Delay_ms(100);

    Soft_UART_Write_Text(text);
}

- - - Updated - - -

can you please send me simple code for sending a string through soft uart to pc
 

Attachments

  • soft uart.rar
    41.9 KB · Views: 90

See the attached file it is working.
 

Attachments

  • SoftUART.rar
    49.4 KB · Views: 94
  • softuart.jpg
    softuart.jpg
    141.3 KB · Views: 107
i implemented some soft uart code in my code and it is transmitting a single character on terminal. i m facing problem in sending a string on terminal
code with simulation attached
 

Attachments

  • final.rar
    121.8 KB · Views: 100

You have posted the project for control-control but not for ballot. The Proteus Simulation has 2 mcu, So, I need the mikroC Project files for ballot mcu. I have to get the ballot.hex for the other mcu. Without that I can't simulate your project.
 
Last edited:
zip file including mikroc pro file and proteus simulation

- - - Updated - - -

i changed the code a little more
Code:
char error, byte_read;
int i;
char text[15]="vote casted";  
void Soft_UART_Write_Text(char *text) {
     unsigned int x = 0;
     for(x = 0; x <= strlen(text); x++) {
         Soft_UART_Write(text[x]);
     }
 }               // Auxiliary variables
void main(){

  //ANSEL  = 0;                             // Configure AN pins as digital I/O
  //ANSELH = 0;

  TRISB = 0x00;                           // Set PORTB as output (error signalization)
  PORTB = 0;                              // No error

  error = Soft_UART_Init(&PORTC, [COLOR="#FF0000"]17, 16,[/COLOR] 9600, 0); // Initialize Soft UART at 14400 bps
  if (error > 0) {
    PORTB = error;                        // Signalize Init error
    while(1) ;                            // Stop program
  }
  Delay_ms(100);

    Soft_UART_Write_Text(text);
}

- - - Updated - - -

can you please send me simple code for sending a string through soft uart to pc

seriously ? your pin numbers on PORTC are Tx= 16 and Rx= 17 ?!? You have to pay more attention to such details Sobia, or you will never be a good embedded programmer.


So the question is... did it work ? :) Even that single character... how did it get through? Was it the correct character ?? wow.
 

the file of ballot
 

Attachments

  • ballot.rar
    25.1 KB · Views: 91

this seems wierd becuase i m compiling that code and it is not giving any ram issue.
 

What is the problem you are facing in the control-control.c code? What is not working?
 

Attachments

  • cc.jpg
    cc.jpg
    282.2 KB · Views: 135
Last edited:

soft uart is working properly on proteus means simulation is happening but when i implemented the same circuit on hardware it is giving me garbage values
 

hi i am also feeling problem in mikroc pro but it is working for me mikroc
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top