Pytania, kody i porady dotyczące nie tylko Bascom.
-
weako
- Posty: 11
- Rejestracja: 22 mar 2020, 14:37
Post
autor: weako » 25 mar 2020, 5:58
Hi Everyone,
I try to modified below code, but i am getting an error, that below code not finish compile.
Could someone here help me to solved what the problem, i am new in basic compiler.
$Regfile="m8def.dat"
$Crystal=8000000
$hwstack=40
$swstack=40
$framesize=40
Rem Configuration of LCD display
Config Lcd = 20 * 2 '2 rows x 20 chars
Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portd.7 , Db6 = Portd.6 , Db7 = Portd.5 , Rs = Portb.2 , E = Portb.1
Cursor Off
Cls
Rem Configuration of ADC
Config Adc = Single , Prescaler = Auto
Rem Declarations of variables
Dim Uref As Word
Dim Uf As Long
Dim Ur As Long
Dim Adjust As Word
Dim Swr1 As Long
Dim Swr2 As Long
Dim Swr As Single
Dim Swr$ As String * 3
Dim X As Single
Dim Pwr As Single
Dim Scale(3) As Byte
Dim X_scale As Byte
Dim Scale_$(3) As String * 4
Dim E_scale As Eram Byte
Dim Multiply As Byte
Const Row = " "
Rem Config and setting ports
Config Pinc.6 = Input
Config Pinc.5 = Input
Config Pind.0 = Output
Config Pinc.0 = Input
Config Pinc.1 = Input
Config Pinc.2 = Input
Set Portc.6
Set Portc.5
Set Portc.4
Set Portd.0
Rem show scale
X_scale = E_scale
GoSub Show_scale
Rem MAIN LOOP
Do
GoSub Read_adc
GoSub Calculate_pwr
GoSub Show_pwr
GoSub Calculate_swr
GoSub Show_swr
Waitms 100
Debounce Pinc.5 , 0 , Scale_sub , Sub
Loop
Rem ===============================
Rem ==== SUBS =================
Rem ===============================
Rem Read ADCs
Read_adc:
Start Adc
Uref = Getadc(1)
Uf = Getadc(0)
Ur = Getadc(2)
Adjust = Getadc(3) 'Calculate variable "Adjust"
Adjust = Adjust * 10
Adjust = Adjust + 54000
Stop Adc
Return
Rem ===Calculate SWR====
Calculate_swr:
Swr1 = Ufi + Ur
Swr2 = Ufi - Ur
Swr = Swr1 / Swr2
Swr$ = Str(Swr)
Swr$ = Left(Swr$, 3)
Swr = Log10(Swr) 'calculate SWR bargraph
Swr = 20 * Swr
Swr = Round(Swr)
If Swr > 15 Then
Swr = 15
End If
Return
Rem ===Show SWR=========
Show_swr:
Locate 2, 1
Lcd Row
Locate 2, 1
For X = 1 To Swr 'show SWR bargraph
Lcd "="
Next
Lcd ">" ; Swr$
Return
Rem ===Calculate PWR===============
Calculate_pwr:
Uf = Uf - Uref
Ur = Ur - Uref
Pwr = Uf ^ 2
Pwr = Pwr / Adjust
If Pwr < 0.05 Then
End If
Pwr$ = Str(Pwr)
Pwr$ = Left(Pwr$, 3)
Pwr = Multiply * Pwr 'calculate PWR bargraph
Pwr = Round(Pwr)
Return
Rem ===Show PWR============
Show_pwr:
Locate 1, 1
Lcd Row
Locate 1, 1
Lcd Pwr$
Return
Rem ===Switch scale of PWR bargraph ========
Scale_sub:
X_scale = E_scale
Incr X_scale
If X_scale > 3 Then
X_scale = 1
End If
GoSub Show_scale
Return
Rem ===Show PWR bargraph scale ============
Show_scale:
Scale_$(1) = "500 W"
Scale_$(2) = "250 W"
Scale_$(3) = "50 W"
Scale(1) = 1
Scale(2) = 4
Scale(3) = 10
Multiply = Scale(x_scale)
E_scale = X_scale 'save PWR bargraph scale into eeprom
Cls
Locate 1, 4
Lcd "BARTEK: " ; Scale_$(x_scale) 'range of bargraf
Wait 3
Return
End
Thank you.
Wea.
-
niveasoft
- Posty: 1216
- Rejestracja: 17 sie 2015, 12:13
-
Kontakt:
Post
autor: niveasoft » 25 mar 2020, 6:16
Now NO ERRORS and compile but for the next time please attach errors from IDE.
In your code variable Ufi was not declared, string Scale_$ was too short (3 chars) Now I change it into 10.
Please do not declare variables like that "Var$" because $ sign is a special character so Var_$ is okay where Var$ is not.
I change some variable names. For example from Pwr$ into Pwr_s.
$Regfile="m8def.dat"
$Crystal=8000000
$hwstack=40
$swstack=40
$framesize=40
Rem Configuration of LCD display
Config Lcd = 20x2 '2 rows x 20 chars
Config Lcdpin = Pin , Db4 = Portb.0 , Db5 = Portd.7 , Db6 = Portd.6 , Db7 = Portd.5 , Rs = Portb.2 , E = Portb.1
Cursor Off
Cls
Rem Configuration of ADC
Config Adc = Single , Prescaler = Auto
Rem Declarations of variables
Dim Uref As Word
Dim Uf As Long
Dim Ufi As Long
Dim Ur As Long
Dim Adjust As Word
Dim Swr1 As Long
Dim Swr2 As Long
Dim Swr As Single
Dim Swr_s As String * 3
Dim X As Single
Dim Pwr As Single
Dim Pwr_s As String * 10
Dim Scale(3) As Byte
Dim X_scale As Byte
Dim Scale_$(3) As String * 10
Dim E_scale As Eram Byte
Dim Multiply As Byte
Const Row = " "
Rem Config and setting ports
Config Pinc.6 = Input
Config Pinc.5 = Input
Config Pind.0 = Output
Config Pinc.0 = Input
Config Pinc.1 = Input
Config Pinc.2 = Input
Set Portc.6
Set Portc.5
Set Portc.4
Set Portd.0
Rem show scale
X_scale = E_scale
GoSub Show_scale
Rem MAIN LOOP
Do
GoSub Read_adc
GoSub Calculate_pwr
GoSub Show_pwr
GoSub Calculate_swr
GoSub Show_swr
Waitms 100
Debounce Pinc.5 , 0 , Scale_sub , Sub
Loop
Rem ===============================
Rem ==== SUBS =================
Rem ===============================
Rem Read ADCs
Read_adc:
Start Adc
Uref = Getadc(1)
Uf = Getadc(0)
Ur = Getadc(2)
Adjust = Getadc(3) 'Calculate variable "Adjust"
Adjust = Adjust * 10
Adjust = Adjust + 54000
Stop Adc
Return
Rem ===Calculate SWRUndeclared identifier Ufi. In File: G:\KOPIE\KOPIA_2019_05_01\Desktop\test_new\waeko.bas; at Line: 89, Position 12====
Calculate_swr:
Swr1 = Ufi + Ur
Swr2 = Ufi - Ur
Swr = Swr1 / Swr2
Swr_s = Str(swr)
Swr_s = Left(Swr_s, 3)
Swr = Log10(Swr) 'calculate SWR bargraph
Swr = 20 * Swr
Swr = Round(Swr)
If Swr > 15 Then
Swr = 15
End If
Return
Rem ===Show SWR=========
Show_swr:
Locate 2, 1
Lcd Row
Locate 2, 1
For X = 1 To Swr 'show SWR bargraph
Lcd "="
Next
Lcd ">" ; Swr_s
Return
Rem ===Calculate PWR===============
Calculate_pwr:
Uf = Uf - Uref
Ur = Ur - Uref
Pwr = Uf ^ 2
Pwr = Pwr / Adjust
If Pwr < 0.05 Then
End If
Pwr_s = Str(Pwr)
Pwr_s = Left(Pwr_s, 3)
Pwr = Multiply * Pwr 'calculate PWR bargraph
Pwr = Round(Pwr)
Return
Rem ===Show PWR============
Show_pwr:
Locate 1, 1
Lcd Row
Locate 1, 1
Lcd Pwr_s
Return
Rem ===Switch scale of PWR bargraph ========
Scale_sub:
X_scale = E_scale
Incr X_scale
If X_scale > 3 Then
X_scale = 1
End If
Gosub Show_scale
Return
Rem ===Show PWR bargraph scale ============
Show_scale:
Scale_$(1) = "500 W"
Scale_$(2) = "250 W"
Scale_$(3) = "50 W"
Scale(1) = 1
Scale(2) = 4
Scale(3) = 10
Multiply = Scale(x_scale)
E_scale = X_scale 'save PWR bargraph scale into eeprom
Cls
Locate 1, 4
Lcd "BARTEK: " ; Scale_$(x_scale) 'range of bargraf
Wait 3
Return
End
-
weako
- Posty: 11
- Rejestracja: 22 mar 2020, 14:37
Post
autor: weako » 25 mar 2020, 8:37
Hi Niveasoft,
Thank you for changes the variable and fix the problem.
After i tested that code, look like not working correctly, i trying this code hex on proteus software, that appears only LCD text BARTEK.
Hope someone here can help more to see what is a problem, please find attached proteus file.
Thank you.
Wea.
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
-
Pikczu
- Posty: 390
- Rejestracja: 17 sie 2015, 13:46
- Lokalizacja: Dublin, Ireland
-
Kontakt:
Post
autor: Pikczu » 25 mar 2020, 15:01
Hi weako
What is the version of the Proteus you are using?
-
weako
- Posty: 11
- Rejestracja: 22 mar 2020, 14:37
Post
autor: weako » 25 mar 2020, 15:20
Hi pkc,
My proteus i use is version 8.9 for SP2.
Thanks.
Wea.