Tuesday, 17 June 2014

microcontroller - Sending integers via PIC's USART


I need to send integers from my micro controller board (PIC16F877) to the PC. I'm using MAX232 for this. I need to use a code similar to this (coded using mikroc 8.2).


Please note that this is not correct (actually the line Usart_Write(count); will not work as intended). But it'll show what I'm trying to do.


#define BAUD_RATE 57600
#define DELAY 500
int count;


void interrupt(){
if(INTCON.INTF == 1 ){
count++;
INTCON.INTF = 0;
}
}

void setup(){
INTCON = 0x90;
TRISB = 0x01;

Usart_Init(BAUD_RATE);
count = 0;
}

void main() {
setup();
while(1){
Usart_Write('>');
Usart_Write(count);
Usart_Write('<');

count = 0;
delay_ms(DELAY);
}
}

The application is simple. The variable counter is incremented with PORTB0 interrupt and counter value is needed to be send to PC.


Can someone show me a correct (and simple) way to do this..




No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...