Define SIMULATION_WAITMS_VALUE = 1
'---------------------------------------------------------------
'DEFININTIONS
'---------------------------------------------------------------
Define CONF_WORD = 0x3f50 'Internal Oscillator'
Define CLOCK_FREQUENCY = 8
AllDigital
'--------------------------------------------------------------
'LCD SETUP
'--------------------------------------------------------------
Define LCD_LINES = 4
Define LCD_CHARS = 20
Define LCD_BITS = 4
Define LCD_DREG = PORTB
Define LCD_DBIT = 4 'Data RB7 - RB4
Define LCD_RSREG = PORTB
Define LCD_RSBIT = 3
Define LCD_EREG = PORTB
Define LCD_EBIT = 2
Define LCD_RWREG = PORTB
Define LCD_RWBIT = 1
Define LCD_READ_BUSY_FLAG = 1
'NOTE RB0 IS USED FOR INTERUPT!!!
Define LCD_COMMANDUS = 5000 'delay after LCDCMDOUT, default value is 5000
Define LCD_DATAUS = 100 'delay after LCDOUT, default value is 100
Define LCD_INITMS = 20
'--------------------------------------------------
'variables
'----------------------------------------------------
Symbol encodera = PORTA.0
Symbol encoderb = PORTA.1
Dim bandwidth_upper As Byte
Dim bandwidth_lower As Byte
Dim freq_step As Byte 'used to set the tuning step 1khz/10khz etc
Dim init_anlg As Byte
Dim anlg As Byte
Dim init_digi_mhz As Byte
Dim init_digi_khz As Byte
Dim init_digi_hz As Byte
Dim digi_mhz As Byte
Dim digi_khz As Byte
Dim digi_hz As Byte
Dim intrcnt As Byte 'number of times interupt is triggered
Dim direction As Bit 'which direction the encoder is turning.
startup:
'------------------------------------------------------
'Clear the LCD and give everyting time to initialise
'------------------------------------------------------
Lcdinit 'LcdCurBlink
Lcdcmdout LcdClear
WaitMs 10
'---------------------------------------------------------------------
'Define the analoug display
'---------------------------------------------------------------------
Lcddefchar 0, %00000, %00000, %00000, %11111, %11111, %00000, %00000, %00000
Lcddefchar 1, %11111, %11111, %11111, %11111, %11111, %11111, %11111, %11111
Lcddefchar 2, %10000, %10000, %10000, %11111, %11111, %10000, %10000, %10000
Lcddefchar 3, %00001, %00001, %00001, %11111, %11111, %00001, %00001, %00001
'--------------------------------------------------------
'Welcome message to LCD
'--------------------------------------------------------
Lcdcmdout LcdLine1Pos(5)
Lcdout "DIGITAL VFO"
Lcdcmdout LcdLine2Pos(7)
Lcdout "by M0TVU"
Lcdcmdout LcdLine4Pos(4)
Lcdout "Version 1.01"
WaitMs 1000 '1000
Lcdcmdout LcdClear
'---------------------------------------------------
'Set initial Values
'----------------------------------------------------
bandwidth_upper = 200
bandwidth_lower = 0
freq_step = 10
init_anlg = 9
anlg = init_anlg
init_digi_mhz = 7
init_digi_khz = 100
init_digi_hz = 0
digi_mhz = init_digi_mhz
digi_khz = init_digi_khz
digi_hz = init_digi_hz
'---------------------------------------------------
'Set interupt values
'----------------------------------------------------
TRISB = 0x00
'adcon1 = 0x84
'T1CON = 0x30 '00110000 - set the prescaler 1:8
'T1CON.T1OSCEN = 1 'oscillator enabled
'T1CON.TMR1CS = 0 'Timer 1 clock source 0= internal clock
'T1CON.TMR1ON = 1 'Enable TIMER 1
'TMR1H = 0xff 'Values for high bit ? Why these values?
'TMR1L = 0xfa 'Valur for low bit ?
INTCON.GIE = 1 'enable all unmasked interupts - unmasked?
INTCON.PEIE = 1 'enable all unmasked peripheral inteupts
INTCON.INTE = 1 'external interrupt on RB0.
'PIE1.TMR1IE = 1 'Enable overflow
'PIR1.TMR1IF = 0 'clear overflow
Enable 'what does this do?
'----------------------------------------------------------------
'MAIN BODY
'----------------------------------------------------------------
loop:
'Give the main code something to do.
Call digi_disp(digi_mhz, digi_khz, digi_hz)
Call anlg_disp(anlg)
Goto loop
End
'----------------------------------------------------------------
'ON INTERRUPT
'----------------------------------------------------------------
On Interrupt
Save System
'interrupt triggers every 1/4 second approx so 4 times = 1 second.
'why aren't interupts disabled here?
PIR1.TMR1IF = 0 'clear the overflow
INTCON.INTF = 0 'clear interrupt on RB0.
intrcnt = intrcnt + 1
'If intrcnt = 2 Then 'interupted 4 times = 1 second?
'intrcnt = 0
'this is where the interupt code would go.
direction = encodera Xor encoderb
If direction = 1 Then 'increment
If freq_step = 10 Then
digi_khz = digi_khz + 10
Endif
If freq_step = 1 Then
digi_hz = digi_hz + 1
Endif
anlg = anlg + 1
Else 'decrement
If freq_step = 10 Then
digi_khz = digi_khz - 10
Endif
If freq_step = 1 Then
digi_hz = digi_hz - 1
Endif
anlg = anlg - 1
Endif
'Endif
'TMR1H = 0xff
'TMR1L = 0xfa
Resume
'----------------------------------------------------------------
'Functions
'----------------------------------------------------------------
Function anlg_disp(arg1 As Byte) As Byte 'this should be a procedure!!
Lcdcmdout LcdLine3Home
Select Case arg1
Case 0
Lcdout 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 1
Lcdout 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 2
Lcdout 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 3
Lcdout 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 4
Lcdout 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 5
Lcdout 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 6
Lcdout 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 7
Lcdout 2, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 8
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 9
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 10
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3
Case 11
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3
Case 12
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 3
Case 13
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 3
Case 14
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3
Case 15
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3
Case 16
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 3
Case 17
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3
Case 18
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3
Case 19
Lcdout 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
EndSelect
End Function
'----------------------------------------------------------------
'Procedures
'----------------------------------------------------------------
Proc digi_disp(arg1 As Byte, arg2 As Byte, arg3 As Byte,)
Lcdcmdout LcdLine1Pos(6)
Lcdout #arg1, "."
Lcdcmdout LcdLine1Pos(8)
Lcdout #arg2, "."
Lcdcmdout LcdLine1Pos(12)
Lcdout #arg3
End Proc