Device = 18f25k22
Clock = 20
Config 'for K-series device
FOSC = HSHP ,'HS oscillator (high power > 16 MHz)
PLLCFG = Off ,'Oscillator used directly
PRICLKEN = Off ,'Primary clock can be disabled by software
FCMEN = Off ,'Fail-Safe Clock Monitor disabled
IESO = Off ,'Oscillator Switchover mode disabled
'PWRTEN = Off ,'Power up timer disabled
PWRTEN = on ,'Power up timer enabled
BOREN = Off ,'Brown-out Reset disabled in hardware and software
'BOREN = on ,'Brown-out Reset enabled
BORV = 285 ,'VBOR set to 2.85 V nominal
WDTEN = Off ,'Watch dog timer is always disabled. SWDTEN has no effect.
WDTPS = 256 ,'1:256
PBADEN = Off ,'PORTB<5:0> pins are configured as digital I/O on Reset
HFOFST = Off ,'HFINTOSC output and ready status are delayed by the oscillator stable status
MCLRE = EXTMCLR ,'MCLR pin enabled, RE3 input pin disabled
STVREN = On ,'Stack full/underflow will cause Reset
'LVP = On ,'Single-Supply ICSP enabled if MCLRE is also 1
LVP = Off ,'Single-Supply ICSP disabled
XINST = Off ,'Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
Debug = Off'Disabled
Include "keypad16pullup.bas"
Include "usart.bas"
Include "convert.bas"
Dim Keypressed As Byte
Dim Keyvalue As Byte
dim Total as word
SetBaudrate(br9600)
DelayMS(5000)
USART.Write ("Test program",13, 10, 10)
Keypressed = 0
total = 0
While 1 = 1
While Keypressed = 0 'print key and exit when key pressed
Keypressed = Keypad16.Value
If Keypressed <> 0 Then
if keypressed = 16 then 'Keypressed = double zero
total = total + 50
USART.Write ("Key pressed = 00"," Total = ", dectostr(total), 13, 10)
else
total = total + keypressed
USART.Write ("Key pressed = ", decToStr(Keypressed), " Total = ", dectostr(total), 13, 10)
end if
End If
Wend
delayms(100)
While Keypressed <> 0 'loop until key not pressed
Keypressed = Keypad16.Value
Wend
Wend