Ok so here the whole code. I was setting the portB.5 to input.
Yes it should just show the constant hen I am not pressing the button. But now it is flipping from to the other without me doing anything.
k
INCLUDE "modedefs.bas"
@ DEVICE PIC16F877a , HS_OSC , WDT_OFF , PWRT_ON , BOD_ON , LVP_OFF , PROTECT_OFF
'HS 20mhz, watchdog off, powerup timer on, mclr external, brown out detect on, low volt program off , code protect off
CMCON = 9 : ADCON1 = 2
DEFINE OSC 20 'use external 20mhz crystal
DEFINE LCD_DREG PORTD ' Set LCD Data port
DEFINE LCD_DBIT 4 ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTC ' Set LCD Register Select port
DEFINE LCD_RSBIT 6 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTC ' Set LCD Enable port
DEFINE LCD_EBIT 7 ' Set LCD Enable bit ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2500
DEFINE LCD_DATAUS 250
DEFINE CHAR_PACING 2000
Pause 2000 ' Wait 2 second
' Define ADCIN parameters
Define ADC_BITS 10 ' Set number of bits in result
Define ADC_CLOCK 3 ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50 ' Set sampling time in uS
DEFINE CCP1_REG PORTC 'Hpwm 1 pin port, RIGHT
DEFINE CCP1_BIT 2 'Hpwm 1 pin bit
DEFINE CCP2_REG PORTC 'Hpwm 2 pin port, LEFT; to enable A
DEFINE CCP2_BIT 1 'Hpwm 2 pin bit
DEFINE HPWM1_TIMER 1
DEFINE HPWM2_TIMER 10
TRISA = %11111111 ' Set PORTA to all input
TRISB = %00111111
TRISC = %00010000
TRISD = %00000000
TRISE = %00000111
ADCON1 = %10000010
battery1 var word
portB = 0
'************************************************* ***************************************
loop:
if portB.5 = 1 then
goto Sub_MicroControllerBatteryCheck
else
goto print
endif
print:
Lcdout $fe, 1 'Clear screen
Lcdout "Left: ", Dec 534
Lcdout $fe, $C0, "Right: ", Dec 999
portB.7 = 1
pause 150
portB.7 = 0
goto loop
Sub_MicroControllerBatteryCheck:
adcin 6,battery1
battery1 = 100-( 10*(1024-battery1) )/20
Lcdout $fe, 1 'Clear screen
Lcdout "Battery1: ", Dec battery1
portB.6 = 1
Pause 150
portB.6 = 0
goto loop
End




Bookmarks