MrDEB
Well-Known Member
working on a Swordfish program to display TOTALS of 3 separate breakfasts that we serve on the first Saturday of each month.
I am trying to get the totals written in the EEPROM but it reads some really weird totals like 6403?
This code works great but in case the batteries take a dump or? the totals in the eeprom would be nice.
using a 4 x 20 LCD
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 6/19/2022 *
* Version : 1.0 *
* Notes : breakfast caculator 6/22/22 *
* : *
*****************************************************************************
}
//Program BREAKFAST CACULATOR
Device = 18F43K22
Clock = 16
// int osc and IO pin libraries
Include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
Include "setdigitalio.bas"
// lcd
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// import LCD library...
Include "utils.bas"
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
Include "LCD.bas"
Include "convert.bas"
Include "EEPROM.bas"
// hardware
Dim Button_1 As PORTB.0 // $8 breakfast
Dim Button_2 As PORTB.1 // $5 breakfast
Dim Button_3 As PORTB.2 // 2x breakfast
Dim Button_4 As PORTB.3// cash totals etc
Dim Cash_Totals As Word //cash totals
Dim Meals_Totals As Word //number of meals sold
Dim Eight_Dollar As Word ' $8 breakfast
Dim Five_dollar As Word ' $5 breakfast
Dim Two_times As Word ' 2x breakfast
Dim Cash As Word ' cash sales
Dim Press As PORTC.2
Dim led As PORTD.0
Dim Value As Byte
Dim Str As String
Sub Sales() //suggestion add each meal $ totals
led = 1
Cls
Cash = (Eight_Dollar * 8) + (Five_dollar * 5) + (Two_times * 3)
WriteAt(1,1,"CASH TOTALS:=$",DecToStr(Cash))
WriteAt(2,1,"$8 BREAKFAST:=",DecToStr(Eight_Dollar)," $",DecToStr(Eight_Dollar *8))
WriteAt(3,1,"$5 BREAKFAST:=",DecToStr(Five_dollar)," $",DecToStr(Five_dollar *5))
WriteAt(4,1,"$3 2xTIME :=", DecToStr(Two_times)," $",DecToStr(Two_times *3))
DelayMS(10000)
Cls
End Sub
main:
// init hdw
// LED port - all outputs 2 LEDs per port in parallel 330 ohm resistor
TRISA = 0
'TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
PORTE=%000
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
'PORTB=%00000000 //pullups
//main:
// init hdw
TRISD = 0 // LED port - all outputs
TRISB = $FF // SW port - all inputs
WPUB = $FF // PORTB pullup mask - all PORTB pullups
INTCON2.bits(7) = 0 // RBPU bit - turn on pullups
Input (Press)
Eight_Dollar = 0
Five_dollar = 0
Two_times = 0
Cash = 0
While true
If Button_1 = 0 Then
Eight_Dollar = (Eight_Dollar + 1)
WriteAt(2,1,"$8 BREAKFAST : =",DecToStr (Eight_Dollar ))
' EE.Write(0,DecToStr (Eight_Dollar ))
DelayMS(200)
Else If Button_2 = 0 Then
Five_dollar = (Five_dollar + 1)
WriteAt(3,1,"$5 BREAKFAST : =" ,DecToStr(Five_dollar))
DelayMS(200)
Else If Button_3 = 0 Then
Two_times = (Two_times + 1)
WriteAt(4,1,"$3 2x times : =",DecToStr(Two_times))
DelayMS(200)
Else If Button_4 = 0 Then //breakfast total meals sold
Repeat
Cash = (Eight_Dollar * 8) + (Five_dollar * 5) + (Two_times * 3)
WriteAt(1,1,"CASH TOTALS:=$",DecToStr(Cash))
WriteAt(2,1,"$8BREAKFAST:=",DecToStr(Eight_Dollar)," $",DecToStr(Eight_Dollar *8))
WriteAt(3,1,"$5BREAKFAST:=",DecToStr(Five_dollar)," $",DecToStr(Five_dollar *5))
WriteAt(4,1,"$3 2xTIME :=", DecToStr(Two_times)," $",DecToStr(Two_times *3))
led = 1
Until Press = 0
Cls
End If
End If
End If
End If
Wend
[/CODE]
[/ICODE]
I am trying to get the totals written in the EEPROM but it reads some really weird totals like 6403?
This code works great but in case the batteries take a dump or? the totals in the eeprom would be nice.
using a 4 x 20 LCD
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 6/19/2022 *
* Version : 1.0 *
* Notes : breakfast caculator 6/22/22 *
* : *
*****************************************************************************
}
//Program BREAKFAST CACULATOR
Device = 18F43K22
Clock = 16
// int osc and IO pin libraries
Include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
Include "setdigitalio.bas"
// lcd
#option LCD_DATA = PORTD.4
#option LCD_RS = PORTD.2
#option LCD_EN = PORTD.3
// import LCD library...
Include "utils.bas"
Include "LCD.bas"
Include "ADC.bas"
Include "convert.bas"
Include "LCD.bas"
Include "convert.bas"
Include "EEPROM.bas"
// hardware
Dim Button_1 As PORTB.0 // $8 breakfast
Dim Button_2 As PORTB.1 // $5 breakfast
Dim Button_3 As PORTB.2 // 2x breakfast
Dim Button_4 As PORTB.3// cash totals etc
Dim Cash_Totals As Word //cash totals
Dim Meals_Totals As Word //number of meals sold
Dim Eight_Dollar As Word ' $8 breakfast
Dim Five_dollar As Word ' $5 breakfast
Dim Two_times As Word ' 2x breakfast
Dim Cash As Word ' cash sales
Dim Press As PORTC.2
Dim led As PORTD.0
Dim Value As Byte
Dim Str As String
Sub Sales() //suggestion add each meal $ totals
led = 1
Cls
Cash = (Eight_Dollar * 8) + (Five_dollar * 5) + (Two_times * 3)
WriteAt(1,1,"CASH TOTALS:=$",DecToStr(Cash))
WriteAt(2,1,"$8 BREAKFAST:=",DecToStr(Eight_Dollar)," $",DecToStr(Eight_Dollar *8))
WriteAt(3,1,"$5 BREAKFAST:=",DecToStr(Five_dollar)," $",DecToStr(Five_dollar *5))
WriteAt(4,1,"$3 2xTIME :=", DecToStr(Two_times)," $",DecToStr(Two_times *3))
DelayMS(10000)
Cls
End Sub
main:
// init hdw
// LED port - all outputs 2 LEDs per port in parallel 330 ohm resistor
TRISA = 0
'TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
PORTE=%000
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
'PORTB=%00000000 //pullups
//main:
// init hdw
TRISD = 0 // LED port - all outputs
TRISB = $FF // SW port - all inputs
WPUB = $FF // PORTB pullup mask - all PORTB pullups
INTCON2.bits(7) = 0 // RBPU bit - turn on pullups
Input (Press)
Eight_Dollar = 0
Five_dollar = 0
Two_times = 0
Cash = 0
While true
If Button_1 = 0 Then
Eight_Dollar = (Eight_Dollar + 1)
WriteAt(2,1,"$8 BREAKFAST : =",DecToStr (Eight_Dollar ))
' EE.Write(0,DecToStr (Eight_Dollar ))
DelayMS(200)
Else If Button_2 = 0 Then
Five_dollar = (Five_dollar + 1)
WriteAt(3,1,"$5 BREAKFAST : =" ,DecToStr(Five_dollar))
DelayMS(200)
Else If Button_3 = 0 Then
Two_times = (Two_times + 1)
WriteAt(4,1,"$3 2x times : =",DecToStr(Two_times))
DelayMS(200)
Else If Button_4 = 0 Then //breakfast total meals sold
Repeat
Cash = (Eight_Dollar * 8) + (Five_dollar * 5) + (Two_times * 3)
WriteAt(1,1,"CASH TOTALS:=$",DecToStr(Cash))
WriteAt(2,1,"$8BREAKFAST:=",DecToStr(Eight_Dollar)," $",DecToStr(Eight_Dollar *8))
WriteAt(3,1,"$5BREAKFAST:=",DecToStr(Five_dollar)," $",DecToStr(Five_dollar *5))
WriteAt(4,1,"$3 2xTIME :=", DecToStr(Two_times)," $",DecToStr(Two_times *3))
led = 1
Until Press = 0
Cls
End If
End If
End If
End If
Wend
[/CODE]
[/ICODE]