Problem with port A of 16f913
Iam making an up down counter using 16f913.Iam not able to make portA pins as input A2,A4,A5
Iam using active low buttons
My code Is:
Code:
DG1 VAR BYTE
DG2 VAR BYTE
DG3 VAR BYTE
DIGIT VAR BYTE
DG VAR BYTE
COUNTT VAR BYTe
N VAR WORD
pbutton var porta.2
ibutton var porta.5
i var byte
temp var byte
NUMB VAR WORD
DEFINE BUTTON_PAUSE 50
ADCON1=0
TRISA=1
TRISB=0
TRISC=%00000111
osccon=$60
N=NUMB
GOSUB DIGITCALC
numb=0
MAIN:
gosub display
if pbutton=0 then UP
IF PBUTTON=0 THEN down
GOTO MAIN
'-------------------------------------------------------------------------
'_____________________________________
UP:
IF NUMB=400 THEN MAIN
numb=NUMB+1
GOSUB DIGITCALC
N=NUMB
GOTO MAIN
'_____________________________________
'_____________________________________
DOWN:
IF NUMB=0 THEN MAIN
numb=NUMB-1
GOSUB DIGITCALC
N=NUMB
GOTO MAIN
'_____________________________________
'_____________________________________
___________
DISPLAY:
'DATA FOR DG1,DG2,DG3 IS PUT ON PORTC AND THE CORRESPONDING
'PINS ON PORTB TOGGLED
'THIS IS DONE 100 TIMES
FOR COUNTT=0 TO 99
PORTB=DG1
PORTC.5=1
PAUSE 1
PORTC.5=0
PORTB=DG2
PORTC.6=1
PAUSE 1
PORTC.6=0
PORTB=DG3
PORTC.7=1
PAUSE 1
PORTC.7=0
NEXT COUNTT
RETURN
'________________________________________________________________
'__________________________________________________________________________
DIGITCALC:
'THIS ROUTINE BREAKS UP THE NUMBER INTO 3 DISTINCT PARTS - DG1,DG2,DG3
'NOTICE THAT ANOTHER SUBROUTINE IS CALLED EACH TIME
DIGIT=0
LP1:
IF N<100 THEN DS1
N=N-100
DIGIT=DIGIT+1
GOTO LP1
DS1:
GOSUB FND
DG1=DG
DIGIT=0
LP2:
IF N<10 THEN DS2
N=N-10
DIGIT=DIGIT+1
GOTO LP2
DS2:
GOSUB FND
DG2=DG
DIGIT=N
GOSUB FND
DG3=DG
return
'__________________________________________________________________________
'__________________________________________________________________________
FND:
'THIS ROUTINE IDENTIFIES THE SEGMENTS TO LIGHT UP
'7 SEGMENTS WIRED UP AS FOLLOWS
'A -PORTC.2
'B -PORTC.3
'C -PORTC.6
'D -PORTC.5
'E -PORTC.4
'F -PORTC.1
'G -PORTC.0
FND0:
IF DIGIT>0 THEN FND1
DG=$3F
GOTO FNDEND
FND1:
IF DIGIT>1 THEN FND2
DG=$6
GOTO FNDEND
FND2:
IF DIGIT>2 THEN FND3
DG=$5B
GOTO FNDEND
FND3:
IF DIGIT>3 THEN FND4
DG=$4F
GOTO FNDEND
FND4:
IF DIGIT>4 THEN FND5
DG=$66
GOTO FNDEND
FND5:
IF DIGIT>5 THEN FND6
DG=$6D
GOTO FNDEND
FND6:
IF DIGIT>6 THEN FND7
DG=$7D '
GOTO FNDEND
FND7:
IF DIGIT>7 THEN FND8
DG=$7 '
GOTO FNDEND
FND8:
IF DIGIT>8 THEN FND9
DG=$7F
GOTO FNDEND
FND9:
DG=$67
FNDEND:
RETURN
'__________________________________________________________________________
Re: Problem with port A of 16f913
Have you disabled analog features on port A?
Robert
Re: Problem with port A of 16f913
Can you tell me whw to active analog features pls.
Re: Problem with port A of 16f913
Actually iam new to microcontrollers.
Re: Problem with port A of 16f913
At these lines at the top of your code. You did not say if your are driving a LCD or LED display?
Code:
DEFINE OSC 4 ' or 8 etc
CMCON0 =%00000111 'COMPARATOR OFF
ADCON0 =%00000000 'ADC off
'SET LCD REGISTERS
LCDCON = 0 'LCD disabled
LCDPS = 0
LCDSE0 = 0 'SEGMENTS 0-7 off
LCDSE1 = 0 'SEGMENTS 8 -15 OFF
LCDSE2 = 0 'SEGMENTS 16 - 23 OFF
Re: Problem with port A of 16f913
I am driving three common cathode seven segment display.I want to put three buttons on PORT A.first button is for increase counts ,second is for decrease count and third is for save count.Buttons are connected at PortA.2 ,portA.4 and portA.5. I am using PortA.0 as ADC in my another program and that program works.Need help.
Thanks
Re: Problem with port A of 16f913
Did you add the lines that I posted? That pic has an LCD driver which uses the pins you are having problems with. It needs to be turned off. Adding these lines
Code:
DEFINE OSC 4 ' or 8 etc
CMCON0 =%00000111 'COMPARATOR OFF
ADCON0 =%00000000 'ADC off
'SET LCD REGISTERS
LCDCON = 0 'LCD disabled
LCDPS = 0
LCDSE0 = 0 'SEGMENTS 0-7 off
LCDSE1 = 0 'SEGMENTS 8 -15 OFF
LCDSE2 = 0 'SEGMENTS 16 - 23 OFF
You have to help yourself we can't write your programs for you, read the data sheet.
Re: Problem with port A of 16f913
I have added .but no result.pls guide me if I have done anything wrong with my program regarding if then... Statement.As I am using active low buttons.
Re: Problem with port A of 16f913
First, TRISA=1 is not what you want. You want to set pins 2 and 5 as input:
TRISA=%00100100
Start counting from right, 0 to 7.
Next, keep things simple. Make a copy of this program and remove all code after MAIN.
Then make 2 LEDs turn on and off by pressing the 2 inputs buttons.
Once that works, add the rest a bit at a time.
Robert
Re: Problem with port A of 16f913