PDA

View Full Version : 3-to-8 Decoder Program



BlackNoir
- 28th December 2005, 19:34
Hi, I'm trying out different things with PICBasic Pro and one of the programs I'm trying to write is a 3-to-8 Decoder. The problem I'm having is with the inputs on PortA. No matter what I do, I can't get them to work. I'm using a 16F628A PIC with a 5V+ fed through a 10k resistor to make my input high. If I use some of PortB as Input, those work, it's just PortA I can't seem to use.

Heres the start of my program. It doesn't actually decode yet, I'll finish that once I get these dang Inputs to work.

Thanks,
BlackNoir



'3-to-8 Decoder

'Initialize variables needed in program
B2 VAR BYTE

'Initialize Port(s)
TRISB = 0 'set port B pins as output (00000000)
TRISA = %00000111


Loop1:


B2 = 0

IF PORTA.0 = 1 Then
B2 = B2 + 1
EndIF

IF PORTA.1 = 1 Then
B2 = B2 + 2
EndIF

IF PORTA.2 = 1 Then
B2 = B2 + 4
EndIF

PORTB = B2

GoTo Loop1

robert0
- 28th December 2005, 19:40
Hi,

Porta is normally set to comparator.
Use this:

CMCON=$07 'NO comparator on PORTA

and pins become bidirectional.
Read carefully the datasheet and how to set mclr pin.

bye
roberto

BlackNoir
- 28th December 2005, 19:51
That did it! Thanks roberto!!