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.

Hey Nigel, LCD code question....

Status
Not open for further replies.

NewGeek

New Member
Im using your LCD code with a PIC16F628. I have it working fine on PORTB rather than PORTA. But how do I specify which pins of PORTB in the program. Your code has it using RB0 - RB7, skipping RB5. I want to use pins RB1-RB7 in order to free up RB0.
Is this possible?
I see how you specify the R/S, E, and RW lines but I cant find anywhere in the code where you specify the pin assignments for the data lines.
 
NewGeek said:
Im using your LCD code with a PIC16F628. I have it working fine on PORTB rather than PORTA. But how do I specify which pins of PORTB in the program. Your code has it using RB0 - RB7, skipping RB5. I want to use pins RB1-RB7 in order to free up RB0.
Is this possible?
I see how you specify the R/S, E, and RW lines but I cant find anywhere in the code where you specify the pin assignments for the data lines.

That's because I don't specify them anywhere, I simply use the bottom four pins and write to the port like this:

Code:
LCD_Cmd		movwf	templcd
		swapf	templcd,	w	;send upper nibble
		andlw	0x0f			;clear upper 4 bits of W
		movwf	LCD_PORT
		bcf	LCD_PORT, LCD_RS	;RS line to 1
		call	Pulse_e			;Pulse the E line high

To clear RB0 for use you would have to shift W before the ANDLW, and change the ANDLW to 0x1E. You would need to do this for every read and write through the LCD routines.

I almost forgot!, you would have to alter the TRIS lines as well, not forgetting the ones in the LCD Busy routines where it switches between read and write.
 
Thanks, let me ask you one more thing....the reason I was trying to free up RB0 is for its interrupt capability. I am using a switch to toggle through several LCD screens. Each screen will display values from a different sensor.
I was simply polling a pin that was wired to a switch. Do you think it would be advantageous to use an interrupt routine instead, with the switch on RB0?
 
NewGeek said:
Thanks, let me ask you one more thing....the reason I was trying to free up RB0 is for its interrupt capability. I am using a switch to toggle through several LCD screens. Each screen will display values from a different sensor.
I was simply polling a pin that was wired to a switch. Do you think it would be advantageous to use an interrupt routine instead, with the switch on RB0?

I wouldn't have thought it would make much difference, there should be plenty of time for polling for a key press every now and again.

Assuming the system is reading sensors and displaying values, you could simply do it in the main loop - as in this crude example:

Code:
Start:
        call Read_Sensors
        call Display_Readings
        call Check_Buttons
        goto Start

If you have a delay routine, for example to take a reading only every five seconds, you would need to include the Check_Buttons routine inside the delay routine, so it's checked at short intervals during the long delay.
 
Yes that is essentially how I have written the code. If it doesnt matter, I'll stick with what I have.

So what do you think would be a good application for interrupts?
 
NewGeek said:
So what do you think would be a good application for interrupts?

Anything which requires them 8)

I don't see the point in adding the complication of interrupts if it can be done easily without them, some things are obviously best done with interrupts, such as a real time clock - which needs to keep going even when the processor is busy doing other things.

Also, if the processor is continually busy, obviously interrupt driven serial or key routines make sense - but often these routines simply set a flag to let the main program know that an interrupt has occured, which I always think rather wastes the idea of interrupts!.

But the majority of PIC programs spend most of their time just wasting time, either in delay routines, or waiting for an event to occur - these are easily coped with by polling rather than interrupts.

An obvious use though is waking a processor from sleep, in that case you have no choice, you must use an interrupt - often 'Interrupt on change on PortB' is used - pressing a button on a remote control for example is an ideal candidate.

Another obvious use is to drive a stepper motor, using regular interrupts from a timer to pulse the stepper.
 
Status
Not open for further replies.

Latest threads

Back
Top