Code:
include "modedefs.bas"
DEFINE OSC 4
DEFINE SER2_BITS 9
DEFINE ADC_BITS 10 ' set number of bits in result
DEFINE ADC_CLOCK 5 ' set clock source
DEFINE ADC_SAMPLEUS 50 ' set sampling time for microseconds
DEFINE LCD_DREG PORTD 'set LCD DATA port
DEFINE LCD_DBIT 4 'set starting DATA bit (0 or 4) if 4-bit
DEFINE LCD_RSREG PORTD ' Set LCD Register Select port
DEFINE LCD_RSBIT 2 ' Set LCD Register Select bit
DEFINE LCD_EREG PORTD ' Set LCD Enable port
DEFINE LCD_EBIT 3 ' Set LCD Enable bit
DEFINE LCD_BITS 4 ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 ' Set command delay time in us
DEFINE LCD_DATAUS 50 ' Set data delay time in us
'CONFIG1H = %11000001 ' Oscillator switchover enabled
' Fail safe clock monitor enabled
' XT oscillator
'CONFIG2L = %00011000 ' Brown out reset voltage setting minimum setting
' Brown-out reset disabled
' Power up timer enabled
'CONFIG2H = %00000000 ' WDT disabled
'CONFIG3H = %00000000 ' MCLR disabled
' Timer 1 configured for High power op
' PORTB4:0 are digital IO
' CCP2 muxed with RB3
'CONFIG4L = %11000000 ' background debugger disabled
' instruction set enstions enabled
' Single suppoly ICSP enabled
' stack full/underflow will not cause a Reset
'CONFIG5L = %00000000 ' code protection bit for all blocks
'CONFIG5H = %11000000 ' Data EEPROM not protected
' Boot block not protected
'CONFIG6L = %00001111 ' no write protection bit for all blocks
'CONFIG6H = %11000000 ' no write protection bit for Data EEPROM
' and Boot Block
' Configuration is write protected
'CONFIG7L = %0000000 ' no protection for table reads
'CONFIG7H = %0100000 ' no protection for table reads for boot block
CMCON = 7
ADCON1 = %00001111 ' Voltage reference Vss
' Voltage reference Vdd
' all pins digital
'ADCON2 = ??? ' this needs to be set up if A to D used
'ANSEL = %00000000 ; all digital
'ANSELH = %00001000 ; AN11 is analog
OSCCON = %01101100 ' internal Osc of 4 MHz
WDTCON = %00000000 ' Watchdog timer is off
TRISA = %11011110 ; define Inputs and Outputs
TRISB = %10101111
TRISC = %00000000
TRISD = %00010000
TRISE = %00000000
PORTA = %00000000
PORTB = %00000000
PORTC = %00000000
PORTD = %00000000
PORTE = %00000000
LATA = %00000000 ' Data latch register
LATB = %00000000 ' Data latch register
LATC = %00000000
LATD = %00000000
LATE = %00000000
INTCON = %00000000
INTCON2 = %10000000 ' PortB pullups disabled
PIE1 = %00000000 ' disable peripheral interrupts
PIE2 = %00000000 ' disable peripheral interrupts
'OPTION_REG = %11100000
'WPUA = %00000000
'WPUB = %00000000
CCP1CON = %00001100 ' setup the PWM module for single output on RC5
'PORTA definitions
TEST_OUTPUT VAR PORTA.0
TRANSMIT_OUT VAR PORTA.4
RECEIVE_IN VAR PORTA.5
'PORTB definitions
FUNCTION_BUTTON VAR PORTB.0
UP_BUTTON VAR PORTB.1
DOWN_BUTTON VAR PORTB.2
SET_BUTTON VAR PORTB.3
'ANALOG_INPUT VAR PORTB.5
'SERIAL_OUTPUT VAR PORTB.6
AD_AN11_VALUE VAR WORD
AD_AN11_VOLT VAR WORD
UP_VENT_SETTING VAR BYTE ' WORD ' ON = VENT
UP_FILL_SETTING VAR BYTE ' WORD ' OFF = Fill
DOWN_VENT_SETTING VAR BYTE ' WORD ' ON = VENT
DOWN_FILL_SETTING VAR BYTE ' WORD ' OFF = Fill
UP_PULSES VAR BYTE
DOWN_PULSES VAR BYTE
CHECKSUM_BYTE VAR BYTE
CHECKSUM_WORD VAR WORD
REC_CHECKSUM_VALUE VAR WORD
DUTY VAR WORD
UP_VALUE VAR word
DOWN_VALUE VAR Word
UP_TRIP_ADJUST VAR WORD
DOWN_TRIP_ADJUST VAR WORD
DECAY_VALUE VAR BYTE ' WORD
TOLERANCE_VALUE_UP VAR BYTE ' WORD
TOLERANCE_VALUE_DOWN VAR BYTE
A0 VAR BYTE
A1 VAR BYTE
A2 VAR BYTE
A3 VAR BYTE
A4 VAR BYTE
C1 VAR Byte
C0 VAR BYTE
C6 VAR BYTE
C7 VAR BYTE
D0 Var Byte
D1 VAr Byte
D2 VAr Byte
D3 Var Byte
i VAR BYTE
MODE VAR BYTE ' used to determine which function
'should be incrementing
' MODE 1 A to D setting
' MODE 2 MIN SETTING
' MODE 3 MAX SETTING
UPDATE VAR BYTE 'UPDATE bit 0, used for returning from Interrupts
'UPDATE bit 1, used to indicate Manual Mode
'Update bit 2, 1 = step 1
'Update bit 3, 1 = step 2
'Update bit 4, 1 = step 3
'Update bit 5, 1 = step 4
'---------- program starts here
' 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,15,16,17, 18,19, 20, 21, 22, 23, 24, 25,26,27,28,29,30,31,32
DATA 16, 0, 30, 0, 25, 50, 50, 0, 0, 200, 0, 0, 0, 0, 16, 0, 2, 0, 29, 0, 9, 96,273, 148, 20, 20, 0, 0, 0, 0, 0, 0,00
TEST_OUTPUT = 1
PAUSE 500
TEST_OUTPUT = 0
PAUSE 500
T2CON = %00000101 ' Turn on Timer2, Prescale=4
' Use formula to determine PR2 value for a 1KHz signal,
' 4MHz clock, and prescale=4. (4E6/(4*4*1E3))-1=249
PR2 = 249 ' Set PR2 to get 1KHz out
' Use formula to determine CCPR1L:CCP1CON<5:4> value for
' ends of range 20% to 80%. (249+1)*4*0.2=200 (20% value)
' (249+1)*4*0.8=800 (80% value)
READ 8, DUTY.HIGHBYTE
READ 9, DUTY.LowBYTE
Pause 10
DUTY = DUTY
loop: CCP1CON.4 = duty.0 ' Store duty to registers as
CCP1CON.5 = duty.1 ' a 10-bit word
CCPR1L = DUTY >> 2
duty = duty + 10 ' Increase duty cycle
Pause 200 ' Wait for LCD to startup
DISPLAY_MODE_SELECT:
GOSUB CLEAR_LCD
LCDOUT "Push Function"
LCDOUT $FE, $C0, " to setup values"
LOOK_FOR_BUTTON_PUSH:
BUTTON FUNCTION_BUTTON, 1, 255, 0, A3, 1, SETUP
BUTTON SET_BUTTON, 1, 255, 0, A2, 1, CONTRAST
'GOSUB MODE_BUTTON_PUSH
PAuse 10
GOTO LOOK_FOR_BUTTON_PUSH
Bookmarks