[REQ] Reading Dip-switches on 628A PortB - Issue on PortB.3 and PortB.4
Hi all.
I want to finish this very simple PIC 16F628A code but I have a mistake I don't understand :
What I need is to read the PortB value (0 - 255) but PortB.3 and PortB.4 return zero everytime.
8 Dipswitches are connected on PortB to VCC and the total value is reported on an serial LCD screen.
I don't use X-tal and nothing else my LCD is connected on the PIC for the moment except 2 resistors between VCC and PortA.2 / PortA.3 for a future I2C use.
My serial transmission is okay @9600 without X-tal and my issue is not there.
I try since 3 days and now all my hairs are on the floor ;O)
I think I need something to add in the head of the code but what ?
Any help is welcome.
Thanx a lot and cheers from France.
Here is my code :
Code:
@ device PIC16F628A, INTRC_OSC_NOCLKOUT, wdt_off, pwrt_on, mclr_off, protect_off 'Utilisable avec PM
Include "modedefs.bas" ' Mode definitions for Serout
CMCON = 7 ' Turn OFF all analog features, all is now digital
; VRCON = 0 ' Disable A/D Voltage reference, I don't need that in this code
; INTCON.7 = 0 ' Disable interrupts, I don't need that in this code
Define OSC 4 ' Set Xtal Frequency
DEFINE I2C_SCLOUT 1 ' I'll use I2C communication
Clear
TRISA = 0 ' All Port A output
TRISB = 255 ' All PortB input
LOW PORTA '
SYMBOL SDA = PORTA.2 ' I2C SDA (R 10k to VCC)
SYMBOL SCL = PORTA.3 ' I2C SCL (R 10K to VCC)
SYMBOL DIP1 = PORTB.0
SYMBOL DIP2 = PORTB.1
SYMBOL DIP3 = PORTB.2
SYMBOL DIP4 = PORTB.3
SYMBOL DIP5 = PORTB.4
SYMBOL DIP6 = PORTB.5
SYMBOL DIP7 = PORTB.6
SYMBOL DIP8 = PORTB.7
LCDPIN Var PORTA.1 ' Serial LCD
ADDR1 VAR BYTE
ADDR1 = $C2 ' Fixed I2C address for PLL 5055
PLLBASE VAR WORD
TMP VAR WORD
PLL VAR WORD
PLLLO VAR PLL.LOWBYTE
PLLHI VAR PLL.HIGHBYTE
FMHZ var WORD
FKHZ var WORD
PLLBASE = 19200 ' Lowest freq
BAUDRATE CON N9600 ' For use with LCD
pause 1000 ' wait for the LCD to startup
MAIN:
TMP = PORTB * 2
PLL = PLLBASE + TMP
I2CWrite SDA,SCL,ADDR1,[PLLHI,PLLLO,$8E] ' send command to PLL
Serout LCDPIN, BAUDRATE,[12] ' Clear screen
Serout LCDPIN, BAUDRATE,["PortB= ", #PORTB] ' Print PortB value (0-255)
Pause 1000
GoTo MAIN
Re: [REQ] Reading Dip-switches on 628A PortB - Issue on PortB.3 and PortB.4
OPTION_REG.7 = 0 'enable pullups
Re: [REQ] Reading Dip-switches on 628A PortB - Issue on PortB.3 and PortB.4
Wow, you are right Dick, with this line, my code work better cause changes on dipswitches are immediately detected.
Thanx for your eye of the tiger :O)
But... PortB.3 and PortB.4 seems to be always unconnected.
I replaced my PIC628A by another one to check if these 2 pins were died and I have the same issue with a new PIC.
Not solved.
Re: [REQ] Reading Dip-switches on 628A PortB - Issue on PortB.3 and PortB.4
Connect the dip switches to GND not Vcc
Enable portb pullups
yourvar var byte
yourvar = portb
yourvar ^ %11111111 'invert all 8 bits of the variable
'send the decimal value of yourvar to LCD screen
Re: [REQ] Reading Dip-switches on 628A PortB - Issue on PortB.3 and PortB.4
Quote:
Originally Posted by
Dick Ivers
Connect the dip switches to GND not Vcc
Enable portb pullups
yourvar var byte
yourvar = portb
yourvar ^ %11111111 'invert all 8 bits of the variable
'send the decimal value of yourvar to LCD screen
Hi Dick,
I did what you said and now, it works like the 1st time, my switches aren't inverted and I have to connect to GND a pin to see its value. With the first mod you gave me, all was inverted and VCC had to be used but it was not a problem for me.
With this small piece of code, I've learned a lot of things but I already have my PortB.3 and my PortB.4 returning every time a zero.
Well... You'll think I'm stupid... I've checked all the hardware, my PIC is not directly connected, there is a DIL support under and I've found this DIL support is defective and have no connection on 2 pins !!!
Yes, it was a hardware error ! Arrrgh.
Your help was really useful, now I know how to have simple pull-ups how to invert bits variable and with this both tips, how to make a pull-down it's better for my PCB.
Thanx a lot, this file is now closed for me.
Re: [REQ] Reading Dip-switches on 628A PortB - Issue on PortB.3 and PortB.4
Quote:
Originally Posted by
RCtech
I've checked all the hardware, my PIC is not directly connected, there is a DIL support under and I've found this DIL support is defective and have no connection on 2 pins !!!
Yes, it was a hardware error !
NEVER happens in a SIM!!! ;):D
RC that is not at you, but to support the SIM guys!!
Re: [REQ] Reading Dip-switches on 628A PortB - Issue on PortB.3 and PortB.4
Quote:
Originally Posted by
cncmachineguy
NEVER happens in a SIM!!!..