Hi All,
I am newbie in this forum, I had problem and stuck with these code, could someone here can help me to solve it my problem, below are my code :
On above code, the button up and down doesn't work properly and reading of the power watt un-correct, LCD appears unstable.
I hope someone want to help me.
Mercy,
Mini.
I am newbie in this forum, I had problem and stuck with these code, could someone here can help me to solve it my problem, below are my code :
'--------------PLL IC PIC16F819--------------------------------
'Declare LCD 16x2
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 0
Define LCD_RSREG = PORTA 'For lcd rs
Define LCD_RSBIT = 2
Define LCD_EREG = PORTA 'For lcd e
Define LCD_EBIT = 3
Define LCD_RWREG = 0 'LCD RW
Define LCD_RWBIT = 0 'RWBIT
'---------------------Delay for LCD -----------------
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 50 'delay after LCDOUT, default value is 50
Define LCD_INITMS = 100 'delay used by LCDINIT, default value is 100
'---------------------Declare PORT ce, ck, da to Connection to Pin SAA1057--------------------------
Symbol ce = PORTB.5 'IC PLL SAA1057 CE,CK,DA
Symbol ck = PORTB.4
Symbol da = PORTB.6
Symbol tx_en = PORTB.7 'TX output to drive VDD to ON the power supply stable
Symbol dn = PORTA.0 'Button Decrease Frequency or Power
Symbol up = PORTA.1 'Button Increase Frequency or Power
Symbol lock = PORTA.4 'Send data IC PLL for LOCK
'---------------------Declaration -------------------------------------
Dim freq As Word
Dim f5 As Word
Dim fshow As Word
Dim fmod As Byte
Dim fhbyte As Byte
Dim flbyte As Byte
Dim change As Bit
Dim tm As Byte
Dim t2 As Byte
Dim vu As Byte
Dim power_1 As Word 'NAME "Power" I GOT ERROR HERE WHAT IS THAT AN ERROR
Dim power_show As Byte
Dim power_mod As Byte
ADCON1 = 0x06
TRISB = %01000000 'PORTB 6 output, other are input
TRISA = %11110011 'PORTA 2&3 output, other are input
'-----PLL data status----------------------------------------------------------------------
ce = 0 'CE=0 ck = 0 'CK=0 da = 0 'DA=0
tx_en = 0 'Status TX OFF
Lcdinit 'Initialisation of LCD
Lcdcmdout LcdClear 'Clear LCD
Lcdout " FM PLL 5 W " 'Write on display
WaitMs 3000 'Waiting for 3 second
change = 1 'Change to up
'------Write on EEPROM ???????? 10-11-----------
Read 10, freq.LB
Read 11, freq.HB
'----------Set frequency 108.0 MHz =1080 2=2160-----------
If freq > 2160 Then 'if more than 108 Mhz
freq = 1750 'then frequency 87.5 MHz
Write 10, freq.LB 'Write Byte low
Write 11, freq.HB 'Write Byte high
Endif
If freq < 1750 Then 'if frequency less than 87.50
freq = 2160 'then frequency 108 MHz
Write 10, freq.LB 'Write Byte low
Write 11, freq.HB 'Write Byte high
Endif
'--------------------------------------------------------------------------------------------------
If da Then 'press Enter
Lcdcmdout LcdClear 'LCD Clear
Lcdout "Frequency Tuning" 'Write on display
While da 'ENTER
WaitMs 20
Wend
WaitMs 100 'Wait for
'--------------------------Read L&H byte-------------------------
Read 10, freq.LB
Read 11, freq.HB
'----------Frequency devided---------
fshow = freq / 20
fmod = freq Mod 20
fmod = fmod * 5
'-------------------------------------------------------------
Lcdcmdout LcdHome 'Prepare for LCD Out
If fmod < 10 Then
Lcdout "-------", #fshow, ".0", #fmod, "Mhz " 'Write on LCD
Else
Lcdout "-------", #fshow, ".", #fmod, "Mhz " 'Write on LCD
Endif
'--------------------------------------------------------------------------------------------------
While Not da 'If not enter
tm = 0 'status 0
'--------------Here are Up button---------------------------------
If up Then
freq = freq + 1
While up
tm = tm + 4
If tm = 64 Then freq = freq + 1
If tm = 128 Then freq = freq + 1
If tm = 192 Then freq = freq + 1
If tm = 0 Then freq = freq + 1
If freq > 2160 Then freq = 1750
fshow = freq / 20
fmod = freq Mod 20
fmod = fmod * 5
Lcdcmdout LcdHome
If fmod < 10 Then
Lcdout "-------", #fshow, ".0", #fmod, "Mhz "
Else
Endif
Wend
Endif
Lcdout "-------", #fshow, ".", #fmod, "Mhz "
'----------Here are down button-------------------------
If dn Then freq = freq - 1
While dn
tm = tm + 4
If tm = 64 Then freq = freq - 1
If tm = 128 Then freq = freq - 1
If tm = 192 Then freq = freq - 1
If tm = 0 Then freq = freq - 1
If freq < 1750 Then freq = 2160
fshow = freq / 20
fmod = freq Mod 20
fmod = fmod * 5
Lcdcmdout LcdHome
If fmod < 10 Then
Lcdout "-------", #fshow, ".0", #fmod, "Mhz "
Else
Endif
Wend
Endif
Lcdout "-------", #fshow, ".", #fmod, "Mhz "
Wend 'When ENTER Write EEPROM 10-11
Write 10, freq.LB
Write 11, freq.HB
change = 1
WaitMs 1000
'Endif ' NAME "Endif" I GOT ERROR HERE
'---------------------------------------------------------------------------------------------
TRISB = %00000000 'All PORTB output
'----------------------------make a loop -------------------------------------------------
loop:
If change Then 'IC PLL
'---------------------------Read EEPROM ---------------------------------------------
Read 10, freq.LB
Read 11, freq.HB
'------------------------------------------------------------------------------------------------
fshow = freq / 20
fmod = freq Mod 20
fmod = fmod * 5
Lcdcmdout LcdHome
If fmod < 10 Then
Lcdout "-------", #fshow, ".0", #fmod, "Mhz "
Else
Lcdout "-------", #fshow, ".", #fmod, "Mhz "
Endif
'------------------ IC PLL SAA1057--------------------------------------------------------
f5 = freq * 5
fhbyte = f5.HB
flbyte = f5.LB
'-------------------IC PLL --------------------------------------------------------------------
For t2 = 1 To 2
da = 0
ck = 0
ce = 0
WaitUs 5
ce = 1
ck = 1
WaitUs 5
ck = 0
'---------------------------------------Byte ---------------------------------------------------
For tm = 1 To 8
da = fhbyte.7
WaitUs 5
ck = 1
WaitUs 5
ck = 0
fhbyte = ShiftLeft(fhbyte, 1)
Next tm
'------------------------------------Byte-------------------------------------------------
For tm = 1 To 8
da = flbyte.7
WaitUs 5
ck = 1
WaitUs 5
ck = 0
flbyte = ShiftLeft(flbyte, 1)
Next tm
'--------------------------------Data status is 0----------------------------
da = 0
ce = 0
WaitUs 5
ck = 1
WaitUs 5
ck = 0
Next t2
'------------Option IC PLL SAA----------------
'send 1101_1101_1001_0101-Word b-> > saa1057 flbyte = %10010101
fhbyte = %11011101
da = 0
ck = 0
ce = 0
WaitUs 5
ce = 1
ck = 1
WaitUs 5
ck = 0
For tm = 1 To 8
da = fhbyte.7
WaitUs 5
ck = 1
WaitUs 5
ck = 0
fhbyte = ShiftLeft(fhbyte, 1)
Next tm
For tm = 1 To 8
da = flbyte.7
WaitUs 5
ck = 1
WaitUs 5
ck = 0
flbyte = ShiftLeft(flbyte, 1)
Next tm
da = 0
ce = 0
WaitUs 5
ck = 1
WaitUs 5
ck = 0
'-------------------------------------------------------------------------------------------------
change = 0
WaitMs 1000
tx_en = 1 'If ready (TX ON) Endif
'------------------------------------------------------------------------------------------------
ADCON1 = 0x00
'------------LCD----------------------------
'------------Calculation for a VU ----------------------------
Adcin 0, vu
vu = vu / 2
If vu > 14 Then vu = 14
'--------------------------------------------------------------
Adcin 1, power_1 'NAME "Power" GET ERROR ---> RF Power Output
'-------Calculation for RF Watt-----------------------
power_1 = power_1 * power_1
power_1 = power_1 / 50
power_show = power_1 / 10
power_mod = power_1 Mod 10
'-------------------------------------------------------------------------------------------------
ADCON1 = 0x06
Lcdcmdout LcdLine2Home
For tm = 0 To vu
Lcdout ">"
Next tm
Lcdout "I "
'-------------------Status LOCK---------------------
If Not lock Then
WaitMs 3000
'--------LOCK ------------
If Not lock Then
Lcdcmdout LcdHome
Lcdout "U" 'I GOT ERROR HERE
change = 1
WaitMs 500
Endif
Endif
'-----------------------------Reading for WATT-----------------------------------------------
Lcdcmdout LcdHome
Lcdout "= "
Lcdcmdout LcdHome
Lcdout "=", #power_show, ".", #power_mod, "w"
WaitMs 100
Goto loop 'looping
Endif
'---------------------------------End of CODE---------------------------------------
On above code, the button up and down doesn't work properly and reading of the power watt un-correct, LCD appears unstable.
I hope someone want to help me.
Mercy,
Mini.