Results 1 to 4 of 4

Thread: PIC 16F877A and Usart

  1. #1
    Registered
    Join Date
    Jan 2009
    Location
    Pakistan
    Posts
    1
    Downloads
    0
    Uploads
    0

    PIC 16F877A and Usart

    Hi All.

    I am relatively new in the world of programming MCUs. I tried to set up a communication between my Pic and Vertual Terminal in Proteus. I wrote the following code in MikroC. But it isnt working. The Vertual terminal displays
    00 00 00 00 00 etc.

    Please tell what to do.
    Here is the code.

    unsigned char txt[8];
    unsigned int i;

    void main() {


    Usart_Init(9600);
    Lcd_Init(&PORTD);

    txt[0]="12";
    txt[1]="20";
    txt[2]="50";
    txt[3]="10";
    txt[4]="40";
    txt[5]="80";
    txt[6]="76";
    txt[7]="48";

    for (i=0;i<8;i++)

    Usart_Write(txt[i]);

    }



  2. #2
    Registered
    Join Date
    Dec 2005
    Location
    Usa
    Posts
    94
    Downloads
    0
    Uploads
    0
    I'm surprised it even compiled.. the arra of chars you have is a character array, not an array of strings, which, by your code example, is what you are thinking it is. try txt[0]='a';
    instead of "a" or "12". The single quotes say use on echaracter, the double quotes says use a null terminated string. so "12" = '1','2', and '\0'.. in memory.
    while 'a' is just the single character 'a'.
    If you want the string "hello" to show up, use
    txt[0]='h';
    txt[1]='e';
    txt[2]='l'
    txt[3]='l'
    txt[4]='o'
    txt[5]='\0'; // this is a zero, not a capital O


    Good luck.
    Horsedorf


  3. #3
    Registered
    Join Date
    Dec 2005
    Location
    Usa
    Posts
    94
    Downloads
    0
    Uploads
    0
    Also, don't forget to use (USART_Data_Ready()) before sending text.. like this..
    for(i=0;i<8 && tx[i] != (unsigned char)0 ;i++){ // For the contents of the array up to
    // a nul element. // or the max size of the array.
    while(!USART_Data_Ready()); // wait for the data set ready line so we don't overrun the uart.
    USART_Write(tx[i]); // then write the character.
    }


  4. #4
    Registered
    Join Date
    Sep 2008
    Location
    Australia
    Posts
    25
    Downloads
    0
    Uploads
    0
    I have made the pcb router board from the following site.

    http://www.cq.cx/pcb-router.pl

    My problem is i have converted the asm file to hex and loaded it to the PIC 16f877a but i can not compile the software.

    Can anyone help me compile the software on the site or show me what software is available for this PIC.


Similar Threads

  1. Using PIC 16F877A to program pneumatics
    By Syphonics in forum PIC Programing / Design
    Replies: 3
    Last Post: 12-22-2006, 12:25 PM

Posting Permissions


 


About CNCzone.com

    We are the largest and most active discussion forum from DIY CNC Machines to the Cad/Cam software to run them. The site is 100% free to join and use, so join today!

Follow us on

Facebook Dribbble RSS Feed


Search Engine Friendly URLs by vBSEO ©2011, Crawlability, Inc.