uart/speak up board
Posted: 11 Feb 2015 08:15
I'm not sure I'm using the uart code correctly in my program. The data ready function is not returning a 1. Is the uart setup right?
/*
* Project name:
LED_Blinking (Simple 'Hello World' project)
* Copyright:
(c) Mikroelektronika, 2011.
* Revision History:
20110929:
- initial release (FJ);
* Description:
This is a simple 'Hello World' project. It turns on/off LEDs connected to
PORTA, PORTB, PORTC, PORTD and PORTE.
* Test configuration:
MCU: PIC18F45K22
http://ww1.microchip.com/downloads/en/D ... 41412D.pdf
Dev.Board: EasyPIC7 - ac:LEDs
http://www.mikroe.com/easypic/
Oscillator: HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
Ext. Modules: None.
SW: mikroC PRO for PIC
http://www.mikroe.com/mikroc/pic/
* NOTES:
- Turn ON the PORT LEDs at SW3.
*/
void main() {
int times=0;
int ii;
char receive;
TRISA = 0; // set direction to be output
UART1_Init(9600);
while(1) {
if (UART1_Data_Ready()) {
receive = UART1_Read();
} else continue;
switch (receive) {
case '1':
times=1; break;
case '2':
times=2; break;
case '3':
times=3; break;
default:
times=0; break;
}
for (ii=0; ii<times; ii++) {
LATA = 0x00; // Turn OFF LEDs on PORTA
Delay_ms(1000); // 1 second delay
LATA = 0xFF; // Turn ON LEDs on PORTA
Delay_ms(1000); // 1 second delay
}
}
}
/*
* Project name:
LED_Blinking (Simple 'Hello World' project)
* Copyright:
(c) Mikroelektronika, 2011.
* Revision History:
20110929:
- initial release (FJ);
* Description:
This is a simple 'Hello World' project. It turns on/off LEDs connected to
PORTA, PORTB, PORTC, PORTD and PORTE.
* Test configuration:
MCU: PIC18F45K22
http://ww1.microchip.com/downloads/en/D ... 41412D.pdf
Dev.Board: EasyPIC7 - ac:LEDs
http://www.mikroe.com/easypic/
Oscillator: HS-PLL 32.0000 MHz, 8.0000 MHz Crystal
Ext. Modules: None.
SW: mikroC PRO for PIC
http://www.mikroe.com/mikroc/pic/
* NOTES:
- Turn ON the PORT LEDs at SW3.
*/
void main() {
int times=0;
int ii;
char receive;
TRISA = 0; // set direction to be output
UART1_Init(9600);
while(1) {
if (UART1_Data_Ready()) {
receive = UART1_Read();
} else continue;
switch (receive) {
case '1':
times=1; break;
case '2':
times=2; break;
case '3':
times=3; break;
default:
times=0; break;
}
for (ii=0; ii<times; ii++) {
LATA = 0x00; // Turn OFF LEDs on PORTA
Delay_ms(1000); // 1 second delay
LATA = 0xFF; // Turn ON LEDs on PORTA
Delay_ms(1000); // 1 second delay
}
}
}