Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic 18452 Usart

Status
Not open for further replies.
I'm attempting to use my Matrix Orbital LCD display with a PIC 18452 USART. The default setting on the LCD is 2400 baud, heres my code:

ORG 0
goto Main

ORG 0x20


Main

call SerialEnable

PrintTest
movlw 'T'
movwf TXREG, A
call Pause

movlw 'E'
movwf TXREG, A
call Pause

movlw 'S'
movwf TXREG, A
call Pause

movlw 'T'
movwf TXREG, A
call Pause

goto PrintTest

;---------------------------------------------------
SerialEnable

;--- enable USART ---
bsf RCSTA, SPEN, A ;enable Serial Port
bcf TRISC, 6, A ;make TX line output
bsf TRISC, 7, A ;make RX line input

;--- enable Asynchronous mode ---
movlw .129 ;2400 baud parameter
movwf SPBRG, A ;load baud rate into generator
bcf TXSTA, BRGH, A ;disable high speed baud rate
bcf TXSTA, SYNC, A ;asynchronous mode
bcf TXSTA, TX9, A ;select 8 bit transmission
bsf TXSTA, TXEN, A ;enable transmission
return

;---------------------------------------------------
Pause clrf 0x01, ACCESS ;clear timers
clrf 0x02, ACCESS
movlw 0x10
movwf 0x03, A

Countdown
decfsz 0x01, F, ACCESS
goto Countdown
decfsz 0x02, F, ACCESS
goto Countdown
decfsz 0x03, F, ACCESS
goto Countdown
return


Keep in mind, this is only test code. I realize I can do a bit test to determine when TXREG is empty. I used a long pause between chars to rule out buffer overrun. My problem is Im not getting TEST on the display. I get the same 4 garbage chars over and over instead. Comparing their ASCII codes, it seems to me that the USART isnt inverting the transmitted bits. I've used bit-banging code on a PIC 16F84A to run this display, and I know it works. I also know it requires the data bits to be inverted, same with the START and STOP bits. I cant test my theory since I cant find a way to invert the START/STOP bits on the PIC18452. I feel like I'm missing something obvious, anyone have any ideas???
 
Unlike bit-banged serial I/O where you can easily code for inverted or non-inverted I/O, the serial peripheral in the 18F452 is inverted.

If you need non-inverted signals on the LCD you'll need to add invertors to the '452.

Good luck. Mike
 
Last edited:
It's also usual to check the UART is empty before you transfer data to it, although presumably you're adding the pause to ensure that?.

Check my RS232 PIC tutorial for how to send data using the UART, I suggest using a subroutine as my tutorial does.

As Mike suggests, does your display require inverted or normal RS232?, the hardware USARTS are designed to feed an inverting MAX232.
 
My LCD requires inverted signals (why cant a standard be standard?? sigh...). The MAX232 was the answer I was looking for. Wanted to make sure I wasnt missing something. Thanks guys!
 
the dude of dudes said:
My LCD requires inverted signals (why cant a standard be standard?? sigh...). The MAX232 was the answer I was looking for. Wanted to make sure I wasnt missing something. Thanks guys!

Either use an inverter (a single NPN transistor and two resistors is all you need) or use a software UART, which allows you to invert or not.
 
Nigel Goodwin said:
Either use an inverter (a single NPN transistor and two resistors is all you need) or use a software UART, which allows you to invert or not.

Nigel, if we were face to face I'd be giving you a big high five! Transistor invertor works like a charm (and SIMPLE too). Thanks for your help! Writing to the lCD in software seems like such a waste when the '452 is built for it!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top