kristt2001
New Member
Hi, i am trying to communicate between a barcode scanner, Unitech MS180 and a PIC 18f452, using the USART. However, there is nothing received when a scan is done. The led at RD0 lights when information is received. also the contents of the RCSTA register was viewed, which shows no information is received. can anyone help please?
#include "p18f452.h"
#include <usart.h>
#include <stdio.h>
void read_scanner (void)
{
RCSTA=0b10010000;
/* 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
*/
while(1)
{
while( ! PORTAbits.RA0 ); //wait for RA0 high
putrsUSART( PORTD ); //write value of PORTD
if(PORTD == 0x80) // check for termination
break; // value
}
PORTDbits.RD0 = 0;
// test light led
TRISDbits.TRISD0 = 0;
PORTDbits.RD0 = 1;
CloseUSART();
}
void main (void){
read_scanner();
}
#include "p18f452.h"
#include <usart.h>
#include <stdio.h>
void read_scanner (void)
{
RCSTA=0b10010000;
/* 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
*/
while(1)
{
while( ! PORTAbits.RA0 ); //wait for RA0 high
putrsUSART( PORTD ); //write value of PORTD
if(PORTD == 0x80) // check for termination
break; // value
}
PORTDbits.RD0 = 0;
// test light led
TRISDbits.TRISD0 = 0;
PORTDbits.RD0 = 1;
CloseUSART();
}
void main (void){
read_scanner();
}