#include "p18f452.h"
#include <usart.h>
#pragma config OSC = XT //Sets the oscillator mode to XT for cristal up to 4MHz or HS=>4MHz */
#pragma config WDT = OFF //Turns the watchdog timer off */
#pragma config LVP = OFF //Turns low voltage programming off */
#pragma config DEBUG = OFF // Compiles without extra debug code */
void read_scanner (void)
{
unsigned char id[10];
RCSTAbits.SPEN=1;
/* Serial Port &
Continuous Receive enabled */
TRISCbits.TRISC6 = 0; // set TX (RC6) as output
TRISCbits.TRISC7 = 1; // and RX (RC7) as input
/* USART Tx off &
USART Rx on */
// configure USART
OpenUSART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,
25 );
/*
baud rate for asynchronous mode(BRGH=1)@9600bps,
yields lower %error=+0.16
SPBRG value = 25
*/
// test light led
TRISDbits.TRISD0 = 1;
while(BusyUSART()){ //if the usart is transmitting
getsUSART(id,10);
PORTDbits.RD0 = 0; // take off led
}
CloseUSART();
}
unsigned char GetRS232(void){
while(!PIR1bits.RCIF); //wait for char to be received
return(RCREG); //and return it
}
void main (void){
read_scanner();
}