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.

LCD not working if an Timer 1 interrupt is programmed (PIC16F628A)

Status
Not open for further replies.

revave

Member
Hello,

I have a little problem with a LCD display.

Just when I use an interrupt from timer 1, then my LCD-display is not working, but contains a row of 'blocks' on row 1. Can it be that the init of the display (lcdinit) will not work if during the init an interrupt appears? The program in the loop works fine.
If I remove the complete parameter code for timer 1, then the LCD works fine.

See below the program code with the interupt and a sample program.

**********************************************************************************
'PIC 16F628A, with 2x16 LCD and 20Mhz crystal
Define CONF_WORD = 0x3f42

AllDigital
TRISB = 0x00 'port b as output
TRISA = 0x07 'first three bits as output
Define CLOCK_FREQUENCY = 20

Define LCD_LINES = 2
Define LCD_CHARS = 16
Define LCD_BITS = 4 'allowed values are 4 and 8 - the number of data interface lines
Define LCD_DREG = PORTB
Define LCD_DBIT = 4 '0 or 4 for 4-bit interface, ignored for 8-bit interface
Define LCD_RSREG = PORTA
Define LCD_RSBIT = 4
Define LCD_EREG = PORTA
Define LCD_EBIT = 3
Define LCD_RWREG = 0 'set to 0 if not used, 0 is default
Define LCD_RWBIT = 0 'set to 0 if not used, 0 is default
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 100 'delay used by LCDINIT, default value is 100

'configure Timer 1
T1CON = 0x30 'prescaler
T1CON.T1OSCEN = 1 'oscilator enabled
T1CON.TMR1CS = 0 'synchronise with oscilator
T1CON.TMR1ON = 1 'enable timer 1
TMR1H = 0x0b 'high byte of countvalue
TMR1L = 0xdc 'low byte of countvalue
INTCON.GIE = 1
INTCON.PEIE = 1
PIE1.TMR1IE = 1
PIR1.TMR1IF = 0

Dim intrcnt As Byte

'ínitialisatie
Lcdinit 0

loop:
'just a simple code for running test
If PORTB.1 = 0 Then
PORTB.1 = 1
Else
PORTB.1 = 0
Endif
WaitMs 1000

Lcdcmdout LcdClear 'clear LCD display
Lcdout "test display"
WaitMs 100

Goto loop

End
______________________________________
On Interrupt 'every 0,1 second
Save System

PIR1.TMR1IF = 0
intrcnt = intrcnt + 1
If intrcnt = 5 Then '= 0.5 second
intrcnt = 0

'just a simple code for running test
If PORTB.0 = 0 Then
PORTB.0 = 1
Else
PORTB.0 = 0
Endif
Endif

TMR1H = 0x0b 'load new values to counter
TMR1L = 0xdc 'load new values to counter

Resume
 
Last edited:
hi,
It runs OK for me in the Oshonsoft Simulator.??

E.
 
Yes, it works in the simulator. In a real device it doesn't work. It is strange that the LCD works fine if the timer configuration is deleted form the source code. That means that the LCD connection is okay. Can it be that the interrupt have some effect on pins of PORTA? (LCD uses PORTB and PORTA). The main code (in the loop) is running... Maybe a problem with LCDINIT and the interrupt??
 
Yes, it works in the simulator. In a real device it doesn't work. It is strange that the LCD works fine if the timer configuration is deleted form the source code. That means that the LCD connection is okay. Can it be that the interrupt have some effect on pins of PORTA? (LCD uses PORTB and PORTA). The main code (in the loop) is running... Maybe a problem with LCDINIT and the interrupt??

hi,
Try moving the LCDINIT to before Enabling the Interrupts.

E.

TMR1H = 0x0b 'high byte of countvalue
TMR1L = 0xdc 'low byte of countvalue
Dim intrcnt As Byte

'ínitialisatie
Lcdinit 0

INTCON.GIE = 1
INTCON.PEIE = 1
PIE1.TMR1IE = 1
PIR1.TMR1IF = 0
 
Last edited:
hi,
Try moving the LCDINIT to before Enabling the Interrupts.

Hi,

I've tried this, but that doesn't have any result.
Then I moved LCDINIT between the LCD configuration and the timer conciguration.
In this case the blocks are gone, but I have some strange characters in the topline.
So it has a little effect, but it isn't fixed yet..
 
A new day, maybe a new progres :)

I've connected all the pins from the display to port B.
This also will not lead to a final solution.

The last thing I've tried is to put the display in 8-bits mode, this also will not give the result that I want.
 
What exactly are you using TMR1 for? The following line seems to hijack RB6 and RB7.
Code:
T1CON.T1OSCEN = 1 'oscilator enabled
From the datasheet:
For the PIC16F627 and PIC16F628, when the Timer1 oscillator is enabled (T1OSCEN is set), the RB7/T1OSI and RB6/T1OSO/T1CKI pins become inputs. That is, the TRISB<7:6> value is ignored.
I think you are also trying to use these pins to drive the LCD. This may be were your problem may lie.
 
@Languer:

Thank you for your reply!
Your explanation gives me the solution. I've failed to read these lines in the manual :) When I connect the datalines in 4-bit mode to RB0-RB3 is works fine.
It is also needed to initialise the display before enabeling the timer, just like Eric said.

So, thank you all for your quick reply's!!

Greetings from Holland,
Reijnko Vast
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top