Hi,
The PIC I'm using 18F46K20, isn't fully supported by Oshonsoft, including the TX (Not sure about RX?)
In another thread, I have explored settings till I found that a SW UART needs (oddly) PORTD.4 to be set to INPUT. I've searched the net, contacted Microchip, (No reply yet) and I've been on the Microchip forum. They couldn't help either, but one of them did start me with some CODE in C to help me write a HW UART, in Oshonsoft BASIC
Here is is:
It's going to be difficult for me, so any help would be welcome.
I almost understand the lines marked <<<<<<<<<
The lines marked ?????????? will need some thought.
Camerart.
.
The PIC I'm using 18F46K20, isn't fully supported by Oshonsoft, including the TX (Not sure about RX?)
In another thread, I have explored settings till I found that a SW UART needs (oddly) PORTD.4 to be set to INPUT. I've searched the net, contacted Microchip, (No reply yet) and I've been on the Microchip forum. They couldn't help either, but one of them did start me with some CODE in C to help me write a HW UART, in Oshonsoft BASIC
Here is is:
It's going to be difficult for me, so any help would be welcome.
I almost understand the lines marked <<<<<<<<<
The lines marked ?????????? will need some thought.
Camerart.
Code:
//Configure EUSART for 9600 baud on an MCU clock of 16MHz
//Mode is asynch 8 bits no parity
'void config_eusart(void)<<<<<<<<<<<<<<<
'{
//Configure I/O pins
TRISC.6 = 1 'triscbits.RC6 = 1; //TX pin
TRISC.7 = 1 'triscbits.RC7 = 1; //RX pin
//Configure EUSART peripheral
//=== TXSTA ===
//x--- ---- CSRC - don't care for asynch
//-0-- ---- TX9 - eight bit mode TX
//--0- ---- TXEN - TX disabled for now
//---0 ---- SYNC - Asynch mode
//---- 0--- SENDB - don't send break
//---- -0-- BRGH - low speed
//---- --x- TRMT - don't care is read only
//---- ---x TX9 - don't care in 8 bit mode
'TXSTA = 0x00;
TXSTA.7 = 0
TXSTA.6 = 0
TXSTA.5 = 0
TXSTA.4 = 0
TXSTA.3 = 0
TXSTA.2 = 0
TXSTA.1 = 0
TXSTA.0 = 0
//=== RCSTA ===
//0--- ---- SPEN - disabled for know
//-0-- ---- RX9 - eight bit mode RX
//--x- ---- SREN - don't care in asynch mode
//---0 ---- CREN - RX disabled for know
//---- x--- ADDEN - don't care in 8 bit asynch mode
//---- -x-- FERR - don't care is read only
//---- --x- OERR - don't care is read only
//---- ---x RX9D - don't care is read only
'RCSTA = 0x00;
RCSTA.7 = 0
RCSTA.6 = 0
RCSTA.5 = 0
RCSTA.4 = 0
RCSTA.3 = 0
RCSTA.2 = 0
RCSTA.1 = 0
RCSTA.0 = 0
//=== BAUDCON ===
//0--- ---- ABDOVF - no auto baud
//-x-- ---- RCIDL - don't care is read only
//--0- ---- DTRXP - data receive normal polarity
//---0 ---- CKTXP - transmit polarity normal (idle high)
//---- 0--- BRG16 - 8 bit baud rate generator
//---- -x-- don't care is unimplemented
//---- --0- WUE - normal operation
//---- ---0 ABDEN - no auto baud
'BAUDCON = 0x00;
BAUDCON.7 = 0
BAUDCON.6 = 0
BAUDCON.5 = 0
BAUDCON.4 = 0
BAUDCON.3 = 0
BAUDCON.2 = 0
BAUDCON.1 = 0
BAUDCON.0 = 0
//Configure baud rate generator for 9600 baud on a 16MHz MCU clock
'SPBRG = 25; 'NEEDS WORKING OUT??????????????????????
'BRGH = 0;'NEEDS WORKING OUT?????????????????????
'}
//Enable transmitter
'void enable_tx(void)<<<<<<<<<<<<<<<<<
'{
TXSTA.5 = 1 'TXEN = 1;<<<<<<<<<<
RCSTA.7 = 1 'SPEN = 1;<<<<<<<<<<<<<<<<<<<<<<<
'}
//Disable transmitter
'void disable_tx(void)<<<<<<<<<<<<<<<<<<<
'{
TXSTA.5 = 0 'TXEN = 0;<<<<<<<<<<<<<<<<<<<<<
'}
//Enable receiver
'void enable_rx(void)<<<<<<<<<<<<<<<<<<<
'{
RCSTA.4 = 1 'CREN = 1;<<<<<<<<<<<<<<<
RCSTA.7 = 1 'SPEN = 1;<<<<<<<<<<<<<<<<<<<
'}
//Disable receiver
'void disable_rx(void)'<<<<<<<<<<<<<<<<<<<<<<<<<<
'{
RCSTA.4 = 0 'CREN = 0;'<<<<<<<<<<<<<<<<<<<
'}
//Enable EUSART - receiver and transmitter controlled by CREN and TXEN
'void enable_eusart(void)
'{
RCSTA.7 = 1 'SPEN = 0;'?????????????????????????
'}
//Disable EUSART - stops receiver and transmitter
'void disable_eusart(void)<<<<<<<<<<<<<<<<<<<<<<<<<<
'{
RCSTA.7 = 0 'SPEN = 0;<<<<<<<<<<<<<<<<<<<<<<<
'}
//Check for a received byte
//Return: 1 - A received byte is available to be fetched
//0 - No received byte available
'int rx_byte_available()'????????????????????????????
'{
'If(pir1bits.RCIF)'????????????????????
'{
'Return 1; //data available'???????????????????
'}
'Else'<<<<<<<<<<<<<<<<<<<<
'{
'Return 0; //no data available'<<<<<<<<<<<<<<<<<<<
'}
'}
//Fetch a received byte
//Parameter: *c - pointer to a buffer for the received byte
//Return: 1 - Valid byte received
//0 - No valid byte received
'int get_rx_byte(unsigned char * C)'????????????????
'{
'unsigned char tempc;'?????????????????????
'If(rcstabits.OERR == 1)'?????????????????
'{
//Overrun error - clear
'rcstabits.CREN = 0;'????????????????????????
'nop() ;?????????????????????????????
RCSTA.4 = 1 'rcstabits.CREN = 1;'<<<<<<<<<<<<<<<<<<<<<<<<
'Return 0; //No valid byte has been received'?????????????????
'}
'While(rcstabits.FERR == 1)'?????????????????????
'{
'tempc = RCREG; //reject bytes with framing error'????????????????????
'}
'If(pir1bits.RCIF) //Check if there is any byte available'?????????????
'{
'tempc = RCREG; //return valid byte'?????????????????????
'* C = tempc;???????????????????
'Return 1; //a valid byte has been received '????????????????????
'}
'Return 0; //no valid byte received '???????????????
'}
//Send a byte
//Parameter: c - byte to be sent
//Return: 1 - Byte sent
//0 - Transmitter busy
'int send_tx_byte(unsigned char C)'????????????????
'{
'If(pir1bits.TXIF == 1)'????????????????????????
'{
//Wait for full an empty transmit shift register (errata workaround)
'While(txstabits.TRMT == 1) ;'??????????????????
'TXREG = C;'????????????????????
'Return 1; //byte sent '??????????????????
'}
'Return 0; //transmitter busy '?????????????
'}