Code:
'-------------------------------------------------------------------------------
' PIC 16F690 Fuses (MPASM)
@ __config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_HS_OSC &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF
'_INTRC_OSC_NOCLKOUT
'-------------------------------------------------------------------------------
' Registers 76543210
OPTION_REG = %10000110 'Pull-Ups OFF, Prescaler TMR0 1:128
ANSEL = %00010000 'Select analog inputs Channels 0 to 7
ANSELH = %00000000 'Select analog inputs Channels 8 to 11
WPUA = %00000000 'Select weak pull-ups
WPUB = %00000000 'Select weak pull-ups
ADCON0 = %10000001 'AD Module is ON, Channel 1
ADCON1 = %00000000 'AD control register
CM1CON0 = %00000000 'Comparator1 Module is OFF
CM2CON0 = %00000000 'Comparator2 Module is OFF
INTCON = %10100000 'INTerrupts CONtrol; GIE=1, T0IE=1
TRISA = %00000000 'Select Input/Output (0 to 5)
PORTA = %00000000 'Set High/Low (0 to 5)
TRISB = %00110000 'Select Input/Output (4 to 7)
PORTB = %00000000 'Set High/Low (4 to 7)
TRISC = %00000001 'Select Input/Output (0 to 7)
PORTC = %00000000 'Set High/Low (0 to 7)
'-------------------------------------------------------------------------------
' Defines
define OSC 8
DEFINE LCD_DREG PORTC 'LCD data port
DEFINE LCD_DBIT 4 'LCD data starting PORT.bit (0 or 4)
DEFINE LCD_RSREG PORTC 'LCD register select port
DEFINE LCD_RSBIT 3 'LCD register select bit
DEFINE LCD_EREG PORTC 'LCD enable port
DEFINE LCD_EBIT 2 'LCD enable bit
DEFINE LCD_BITS 4 'LCD bus size 4 or 8
DEFINE ADC_BITS 10 'Number of bits in ADCIN result
'-------------------------------------------------------------------------------
' Init display
' ELECTRONIC ASSEMBLY DOGM081 LCD display Mandatory settings
' See datasheet for circuitry changes by 5V or 3,3V operation
pause 1000 'Time to settle Vdd (THIS IS CRUCIAL!!!)
lcdout $FE, $29 'Function Set: 4 bits bus mode
lcdout $FE, $1C 'Bias set
lcdout $FE, $52 'Power control + Contrast (HiByte)(for 5V=$52 or 3,3V=55)
lcdout $FE, $69 'Follower control (5V=$69/3,3V=6D)
Lcdout $FE, $78 'Contrast (LowByte)
' Custom Characters
lcdout $FE,$28 'Function Set change - ONLY valid for ST7036 controller based LCDs
LCDOUT $FE,$40,$02,$06,$1A,$1A,$1A,$06,$02,$00 'Char 0 = Speaker
LCDOUT $FE,$48,$00,$0A,$0A,$00,$00,$11,$0E,$00 'Char 1 = Smile
LCDOUT $FE,$50,00,00,00,00,00,00,00,00 'Char 2
LCDOUT $FE,$58,14,27,17,17,17,17,31,00 'Char 3 = Battery 1/5 full
LCDOUT $FE,$60,14,27,17,17,17,31,31,00 'Char 4 = Battery 2/5 full
LCDOUT $FE,$68,14,27,17,17,31,31,31,00 'Char 5 = Battery 3/5 full
LCDOUT $FE,$70,14,27,17,31,31,31,31,00 'Char 6 = Battery 4/5 full
LCDOUT $FE,$78,14,31,31,31,31,31,31,00 'Char 7 = Battery 5/5 full
lcdout $FE,$29 'Function Set change
'-------------------------------------------------------------------------------
' Variables
CLEAR
SoftSwitch var PORTA.2
SoftSwitch = 1
Btn1xMinute var PORTB.4
Btn5xMinute var PORTB.5
'******* DEBUG ******
LED_Alarm var PORTB.6
LED_Alarm = 0
LED_RUN var PORTB.7
LED_RUN = 0
'******* DEBUG ******
Bat_Enable var PORTC.1
Bat_Enable = 0
Bat_Port var BYTE
Bat_Port = 4 'PORTC.0 - AN4
Bat_Level var byte 'for LCD character selection (3:7)
Bat_Level = 7
Bat_Value var word 'holds ADC value
Bat_Value = 0
Minutes var byte
minutes = 0
Seconds var byte
Seconds = 0
Ticks var byte
Ticks = 0
Dsp_Upd var bit 'Display Update Allowance
DSP_Upd = 1
Alarm var bit
Alarm = 0
Cnt_A var word
Cnt_a = 0
RUN var bit 'timer is running
RUN = 0
IdleCounter var byte 'counter that increments while timer is 00:00
IdleCounter = 0
'-------------------------------------------------------------------------------
' Start program
'******* DEBUG ******
TEST:
ADCIN 13, Bat_value
lcdout $FE,2,"B ",dec4 Bat_Value
GOTO TEST
'******* DEBUG ******
END
Bookmarks