Page 1 of 2
GLK12232 and RS232 Communication project
Posted: Sun Dec 01, 2002 11:14 pm
by Dexter
well, im back on the horse to trying to get my big PIC project working.
I was going to use the GLK on the PIC's I2C bus, but I figured it would be better to first get it going on the PIC's internal USART.
So, I got the PICs USART talking to my PC perfectly. Connected to COM1, 19.2k, 8N1, no flow control. Press a button, and "Hello" appears on my HyperTerminal.
I hooked up the GLK to COM2, opened up a HyperTerminal Session. 19.2k, 8N1, no flow control. Typed a couple letters. "asdf" appears on my LCD. excellent.
So i hooked up the PIC directly to the LCD, but nothing will show up. What happens is contrast of the screen goes up a bit. Shouldn't I be seeing "Hello" display on my LCD? I don't understand...if the PIC can talk to my PC port, and the PC can talk to the LCD, shouldn't the PIC be able to talk to the LCD?
The PIC is a 16F877 on a Microchip PICDEM2 Plus demo board, with MAX232A installed on it for serial communication.
I have a 1 millisecond delay between each character send. I've tried 5ms, but haven't tried no delay yet.
The only other thing I can think of would be the PIC to LCD cable...but...I am pretty sure it is working.
One last thing, it seems the GLK is trying to send some data back to the PIC for some reason. I have my PIC programmed to display on LEDs any data recieved, and after I send anything to the GLK, I get some data back. It flashes too fast for me to get it all, but the last byte of data is "00001010". I don't know if that means anything. It doesn't make sense, because when you send data to the GLK via PC/Hyperterminal, you don't get anything back
If anyone has any ideas or links to some places that have used this LCD in conjunction with a PIC, please post them.
Thank you

Posted: Sun Dec 01, 2002 11:19 pm
by Henry
PIC ---> PC no problem
PC ---> LCD no problem
PIC ---> LCD problem
Correct?
Posted: Sun Dec 01, 2002 11:21 pm
by Henry
post some of your code when you talk to the LCD...
Posted: Sun Dec 01, 2002 11:31 pm
by Dexter
Henry wrote:post some of your code when you talk to the LCD...
Code: Select all
list p=16F877
Title "USART Demo Program"
;
;This program runs on the PICDEM-2 demo board.
;In the Demo board, Port B is connected to 8 LEDs.
;When the PIC16F877 receives a word of data from
;the USART, the value is displayed on the LEDs and
;is retransmitted to the host computer.
;
include <P16F877.INC>
__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON & _LVP_OFF
CBLOCK 0x20
COUNT, DELAY,DELAYTMP, ; delay function variables...
ENDC
DELAY_MILLI macro TIME
movlw TIME
movwf DELAY
call DELAY_MS
endm
DELAY_MICRO macro TIME
movlw TIME
movwf DELAY
call DELAY_US
endm
SEND macro CHAR
movlw CHAR
movwf TXREG
DELAY_MILLI 5
endm
GREET macro
SEND 'H' ;call send macro, pass it H
SEND 'e'
SEND 'l'
SEND 'l'
SEND 'o'
endm
;
org 00h ;Reset Vector
goto Start
;
org 04h
goto IntVector
org 05h ;Beginning of program EPROM
;----------------------------------------------------------------------------------------
; Subroutines
;----------------------------------------------------------------------------------------
DELAY_US ; busy wait of DELAY us
; 200ns instruction period assumed
nop ; (1)
nop ; (2)
decfsz DELAY,f ; test DELAY count (3)
goto DELAY_US ; loop if not done (4,5)
return ; gtfo (4,5)
DELAY_MS ; busy wait of DELAY ms
; dependant upon DELAY_US being accurate
movf DELAY,w
movwf DELAYTMP ; save DELAY time
DELAY_MS_LOOP ; inner loop
movlw 245 ; load 245 (1)
movwf DELAY ; into DELAY (2)
call DELAY_US ; wait 245us (3-249)
movlw 245 ; load 245 (250)
movwf DELAY ; into DELAY (251)
call DELAY_US ; wait 245us (252-498)
movlw 245 ; load 245 (499)
movwf DELAY ; into DELAY (500)
call DELAY_US ; wait 245us (501-747)
movlw 246 ; load 246 (748)
movwf DELAY ; into DELAY (749)
call DELAY_US ; wait 246us (750-997)
decfsz DELAYTMP,f ; test DELAYTMP count (998)
goto DELAY_MS_LOOP ; loop if not done (999,1000)
return ; gtfo (999,1000)
Start
clrf PORTB ;Clear PORT_B output latches
bsf STATUS,RP0
movlw b'00000001'
movwf TRISB ;Config PORT_B as all outputs
movlw b'00100000' ;Enable RCIF interrupt
movwf PIE1
movlw 0Ch ;19200 baud @4MHz
movwf SPBRG
movlw b'10100100' ;Async, High baud rate
movwf TXSTA
bcf STATUS,RP0
movlw b'10010000' ;Enable continous reception
movwf RCSTA
movlw b'11000000' ;Enable global interrupts
movwf INTCON
GREET ; greetings message
Loop
goto Loop ;wait for recieve interrupt
IntVector
movlw 06h ;Mask out unwanted bits
andwf RCSTA,W ;Check for errors
btfss STATUS,Z
goto RcvError ;Found error, flag it
btfss PIR1,5 ;Check for data ready
retfie ;Some other interrupt, exit
movf RCREG,W ;Get input data
movwf PORTB ;Display on LEDs
movwf TXREG ;Echo character back
movlw h'0D'
movwf TXREG
movlw h'0A' ;newline
movwf TXREG
retfie
RcvError
bcf RCSTA,4 ;Clear reciever status
bsf RCSTA,4
movlw 0FFh ;Light all LEDs
movwf PORTB
retfie
end
Posted: Sun Dec 01, 2002 11:32 pm
by Dexter
basically, i press the reset button on the PICDEM2 board to send the data.
Posted: Sun Dec 01, 2002 11:33 pm
by Henry
you have to make it hard for me here don't you, can't use C or C++...
I will get the head engineer to look at it tomorrow morning with me... unless some one with assembly know how comes by...
Posted: Sun Dec 01, 2002 11:37 pm
by Dexter
Henry wrote:you have to make it hard for me here don't you, can't use C or C++...
I will get the head engineer to look at it tomorrow morning with me... unless some one with assebly know how comes by...
heheh i dont have any C/C++ compliers for PICs. sorry about that, heh.
thanks for the superfast response though!

Posted: Sun Dec 01, 2002 11:47 pm
by Henry
I'm up.. not sure why, but I am

I haved used the CCS compiler of the PIC... and I have a ICE here, very nice to have... but the CCS compliler is a pain in the but, not following any rules, and some times you end up having problems because a long isn't really a long...

Posted: Mon Dec 02, 2002 12:16 am
by Dexter
ive tried CSS i think...maybe Hitech PICC or something...something you had to pay for and something i only had the demo of.
what is an ICE?
Posted: Mon Dec 02, 2002 12:21 am
by Henry
CCS costs money and then you have to pay for patches, and he generaly ends up breaking something with the patch, so youhave to wait till the next patch, read their forums, it's almost comical...
it's a pic emulator, all you do is attach a pod to the development board, and then just run your software on the PC and it emulates the PIC...
Posted: Mon Dec 02, 2002 11:19 am
by Dexter
See, i have RS232 communication and I2C bus working now
temp sensor is Microchip TC74A5
now id just like to get it up on my GLK

Posted: Mon Dec 02, 2002 12:20 pm
by Henry
Switch your Rx and Tx lines...
Posted: Mon Dec 02, 2002 7:04 pm
by Dexter
Henry wrote:Switch your Rx and Tx lines...
tried that
when the LCD is connected to the PIC, it seems like it "locks" the PIC up.
I have an LED set to turn on at powerup. with no LCD connected, it turns on fine. Whent he LCD is connected, the LED doesnt turn on. if i disconnect the LCD, reset the PIC so the LED comes on, and then plug the LCD in, it will turn off and just sit there.
Posted: Mon Dec 02, 2002 8:57 pm
by Henry
Are you working on TTL levels or RS232 levels on the PIC and the GLK?
{edit} well, of course you are talking to the LCD at RS232 level, since you can talk to it from the computer... now the question is, are you talkingto it at TTL levels from the PIC?
Posted: Tue Dec 03, 2002 1:44 am
by Dexter
Henry wrote:Are you working on TTL levels or RS232 levels on the PIC and the GLK?
{edit} well, of course you are talking to the LCD at RS232 level, since you can talk to it from the computer... now the question is, are you talkingto it at TTL levels from the PIC?
im not sure what you mean...
PIC - TTL -> MAX232A -> RS232 - LCD
an idea just popped into my head...i think it has to do with the cable, possibly some pins need to be grounded/connected to each other...i will experiment