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.

reading porta in binary

Status
Not open for further replies.

pixman

Member
I want to use a pic16f628 to drive a lcd for fault display from a PLC.
The problem is that there will be 40 different faults.
is it possible to use a binary type input to porta and read the inputs to go to the different message.
in other words if porta ra0 is high message 1 is shown.
if pin ra1 is high then message 2
if pin ra0 & ra1 high then message 3
by doing this I can have up to 255 messages from 8 inputs
So on if you could help me with simple code and i could work it out from there.

thanks
 
Simply create a table and look down the table for a sub-routine that displays the message on the LCD. Nothing could be simpler.
 
Not to sound dumb but how do you do this.
Is there a tutorial or example that i can modify to do this.
 
Not to sound dumb but how do you do this.
Is there a tutorial or example that i can modify to do this.
Look at Nigel's Tutorials, the link near my signature.
 
You would need to use a chip with more memory but a simple lookup table would work,
Code:
PutMessage	clrf	count
MessLoop	call	Table
		;write to LCD here
		incf	count,f
		btfss	count,4
		goto	MessLoop
		return

Table		movfw	MessageNumber	;get message number
		movwf	temp		;store it
		clrf	PCLATH		;clr high byte of PC
		bcf	STATUS,C	
		rlf	temp,f		;multiply by 16 to get
		rlf	PCLATH,f		;offset in table
		rlf	temp,f
		rlf	PCLATH,f
		rlf	temp,f
		rlf	PCLATH,f
		rlf	temp,f
		rlf	PCLATH,f
		movlw	high Mess1	;add start of table
		addwf	PCLATH,f		;to high byte
		movfw	temp		;get low byte
		addwf	count,w		;and add count
		btfsc	STATUS,C
		incf	PCLATH,f
		addlw	low Mess1		;and add start of table
		btfsc	STATUS,C
		incf	PCLATH,f
		movwf	PCL		;do jump

;each message must be 16 characters long

		org	0x400

Mess1		dt	"0123456789abcdef"
		dt	"Message 2       "
		dt	"Message 3       "

It basically calculates the address of the required message and jumps to it.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top