CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

help me to run program for PIC16F886 interface with uart

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
micky2406



Joined: 29 Sep 2013
Posts: 1

View user's profile Send private message

help me to run program for PIC16F886 interface with uart
PostPosted: Sun Sep 29, 2013 10:49 pm     Reply with quote

here i attached the code. i used MPLAB ICD3 for programming with H-tech compiler. i am not able to receive any data from this code. please help me

#include <pic.h>
#include <stdlib.h>
#include <stdio.h>


unsigned char cUART_char;
unsigned char cUART_data_flg;
void init_uart(void);
void UART_putc(unsigned char c);
void InterruptHandlerLow ();

void main(void){
TRISA = 0;
PORTA = 0;
TRISB = 0;
PORTB = 0;
ANSELH = 0;
ANSEL=0X00;
cUART_char=0X61;
init_uart(); // init UART module

while (1) // infinite loop which handles ncoming data as they arrive
{
UART_putc(cUART_char);
if (cUART_data_flg==1)// if new data available, send it back through USART tx line (echo it)
{
UART_putc(cUART_char);
cUART_data_flg=0; // clear new data flag so one charactor will echoed once
}
}
}
#pragma code
#pragma interrupt InterruptHandlerLow

void InterruptHandlerLow ()
{
if (RCIF==1)
{
if(RCSTA&0x06)
{
CREN=0; //Overrun error (can be cleared by clearing bit CREN)
cUART_char=RCREG; //clear Framing error
CREN=1;
}
else
{
cUART_char = RCREG; // read new data into variable
cUART_data_flg = 1; // new data received. so enable flg
}
}
}

void init_uart(void)
{
TRISC7=1; //Make UART RX pin input
TRISC6=0; //Make UART TX pin output
SYNC = 0; // enables for asynchronous EUART
SPEN = 1; // enables EUSART and sets TX (RC6) as output; ANSEL must be cleared if shared with analog I/O
CREN = 1;
TX9 = 0; // 8bit mode RX9 = 0;
TXEN = 1; // enables Transmitter
BRGH = 1; // baud rate select BRG16 = 0;
SPBRG = 25; //baud rate select 9600@4Mhz SPBRGH = 0;
RCIE=1; // receive interrupt enable
GIE=1; // global interrupt enable
PEIE=1 ; // Peripheral Interrupt Enable bit
}

void UART_putc(unsigned char c)
{
TXEN=0;// disable transmission
TXREG=0x61; // load txreg with data
TXEN=1; // enable transmission
while(TRMT==0) // wait here till transmit complete
{
}
}
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Sun Sep 29, 2013 11:33 pm     Reply with quote

You will have to ask on the HiTech forum as this forum are for PICC users.

Regards
temtronic



Joined: 01 Jul 2010
Posts: 9163
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Sep 30, 2013 6:04 am     Reply with quote

yeesh...this confirms why I chose CCS C compiler a few years ago(V2.5xx)! Just a couple lines of CCS does ALL that....and WORKS first time!!


jay
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group