Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help with learning pic programming

Status
Not open for further replies.

No1Daemon

Newbie level 5
Joined
Apr 15, 2011
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,388
Hi all

I am stepping into the world of pic microcontroller programming and have selected my first project.(not counting flashing leds and switch debouncing etc which I have already done)

I have a pickit2 programmer and am planning on writing the pic code for this circuit Simple-Timer

Here it is used as an rc switch, I basically want to use the same principle for a reed switch activated switched timer with a relay to control the motor of a fishing torpedo.

Electronically it does everything I want. There is a voltage regulator to supply safe voltage to the pic and also for use with the resistor dividers to perform the adc. I believe I will change the transistor to a 30A relay and mosfet.

Here in New Zealand we use Kontikis like in the following page
Home | Seahorse Kontiki's - Home of Kontiki Beach Fishing to haul a fishing line and hooks out to sea. They are powered by 12v batteries in parallel and a trolling motor.

I found the circuit I am planning to use while browsing the internet.

I have made my Kontiki and now I need to work on the circuit.

I need to program the timer from 5 to 30 minutes incremented in 5 minute stages
Then open the relay to start the motor (I am also going to try to implement a delay here to allow me to get to the waters edge first)
I then start the motor timer and countdown the set period until the timer has elapsed and then shut off the motor
There are a number of other functions involved also. The low voltage cutoff to protect the battery and the setting of both the low voltage cutoff level and programming of the countdown time etc.

So I think I need to learn several areas of programming

ADC for the battery monitoring etc
EEprom so I can store the lvc and the delay settings
Timers so I can learn easy ways to set up the timer

I think I will learn assembly as it seems to be easiest to understand for me for some reason. I may branch out to c later on

I realise this is a huge job to take on but please don't discourage me. I intend to learn it slowly a piece at a time

Just posting here to see if anyone can recommend some good tutorials or examples of pages specific to what I need to learn. Any advice to a struggling artist would be appreciated!

Will post my evolving code here later for criticism/comments.

Thanks
Steve
 

have a look at
Microcontrollers Project Examples
**broken link removed**
**broken link removed**

I would recommend you use C - apart from trivial or specialised projects it is easier to build systems and there is plenty of example code for you to use
 

Thanks horace1

I have seen both the links you refer to but I need something more specific. I could(and have) browsed the net for months but I need to narrow it down to specifics related to my project now.

I cant seem to get my head around c yet. I have 2 books on the subject but it's not going in.
I will return to them and have another go.
Any good tutorials you could recommend?
 

Its a professional item your building, but I think you have every chance of pulling that off.
Let me just say though it would be cheaper and a lot quicker to go and buy one, I presume theres another reason for doing it.

An 8 pin 12f675 would be cool for that job, I'd be inclined to write a subroutine for an exact 1 minute delay, then use that with another sub that counts down the set time, calling the minute delay inbetween.
The battery voltage check could be integrated into the 1 minute delay routine, then you'd have a regular battery check interval.

I'd use mosfets to control the motor directly, but thats probably not so wise for a newbie, a relay is a good idea, dont forget to supress the motor, the noise it makes might crash the pic, esp when the relay fires.

Put a 100nf 400v mkt or class x capacitor acrros the motor supply connections at the motor, and then put another 100nf from the - supply terminal to the motors metal case, and another from the + terminal to the case, this'll quiten the motor down electrical noise wise.
You could also put a 100nf class x inseries with a 100ohm resistor across the relay contacts to suppress the spark, this will also reduce rfi and make the relay last longer.
Run supply wires for the pic control circuit to the battery seperately to the motor wiring, or use a seperate control battery.
 
Last edited:

Thanks very much dr pepper
It would be cheaper to buy one. The web site I got the idea from has pre programmed chips for $25 but where's the fun in that?
I assume all those extra caps are only due to interference from the motor and would be not needed with a separate battery source? may be the easy way to go for me.
Had a look at the above c links last night. They are tough. Straight into integers, variables, constants and logic statements much like programming a pc. At least with assembly tutorials you can see what effect you are having and what part of the chip you are controlling straight away.
I think I will study it as an aside while I try to write a program in asm.
 

You still need the caps even with a seperate battery, a 30amp motor will create a lot of hash inclcuding radio frequency noise, filtering the motor is a good idea, you could shiled the control pcb but reducing the noise at source is better.
C is a very good language, and it works on pretty much any processor, esp the pic range, that said of you want to get into pics then learn asm first, thats just my opinion though, when I was learning this at tech they went right into micro assembler, things have changed since then.
 

Hi again

I found some code that performs a load of the functions I require. I had to convert it to assembly from c but it didn't convert particularly well.
Its mostly there but there are a few functions that didn't seem to translate very well. Such as typedef and there are a few instances where a line starts with void which I understand from c but I am not sure if the author is trying to define something or not.
Could someone have a quick look for me please.
Once I have it sorted I can break it down and remove the functions I don't need and edit it to my needs.


I have gone through and removed all the unneccesary numbers and commented out the lines that needed it.
Code:
;//PREPROCESSOR =================================================================

		#include "P12F683.INC"

;//Core configuration options:
		__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO

;//VARIABLES ====================================================================

#define plex1 gpio.0                //GP0 (pin7)        Charlieplex port 1
#define plex2 gpio.1                //GP1 (pin6)        Charlieplex port 2
#define plex3 gpio.2                //GP2 (pin5)        Charlieplex port 3
#define push gpio.3                        //GP3 (pin4)        Push-button
#define fet gpio.5                        //GP5 (pin2)        FET output
typedef unsigned char  u8;        //Defines u8 as an unsigned char type (8bits)
typedef unsigned short u16;        //Defines u16 as an unsigned short type (16bits)

u16        batt;                                        //Voltage of battery being monitored
bit        disp;                                        //Flag set in interrupt for displaying volts

;//Functions declared and explained
;void measure_battery();                //ADC function to measure 12v battery
;void interrupt();                        //Push-button triggers interrupt to reveal voltage via LEDs
;void display_volts();                //Displays voltage via LEDs
;void led1 (bit state);                //Enables individual LEDs... (state: 1=on; 0=off)
;void led2 (bit state);
;void led3 (bit state);
;void led4 (bit state);
;void led5 (bit state);
;void led6 (bit state);
;void eeprom_write();                //Writes test data to EEPROM


;//FUNCTIONS ====================================================================

;void interrupt()                //Interrupt function when push-button is pressed


disp = 1;                                //Set display flag
 	BCF STATUS, RP0
 	BSF gbl_disp,0

        intcon.0 = 0;                        //GPIF: Clear interrupt bit to allow re-use
  	BCF gbl_intcon,0


	SWAPF Int1BContext+D'2', W
	MOVWF FSR
 	SWAPF Int1BContext+D'1', W
 	MOVWF PCLATH
  	SWAPF Int1BContext, W
 	MOVWF STATUS
	SWAPF Int1Context, F
	SWAPF Int1Context, W
	RETFIE


;//-----------------------------------------------------------------------------

void measure_battery()        //Function to trigger ADC conversions to measure 12v battery


u8 i;                //Counter

;//Run ADC
        for(i=0; i<1; i++);                        //Delay for acquisition capacitor to u8ge (1 = ~14uS)
  	BCF STATUS, RP0
  	CLRF measure_ba_00013_1_i
       label9
  	MOVLW 0x01
  	SUBWF measure_ba_00013_1_i, W
 	BTFSC STATUS,C
 	GOTO	label10
 	INCF measure_ba_00013_1_i, F
 	GOTO	label9
      label10

        pir1.6 = 0;                                        //Clear the ADC Complete flag
  	BCF gbl_pir1,6

        adcon0.1 = 1;                                //GO: Start ADC acquisition
  	BSF gbl_adcon0,1

        while(pir1.6==0);                        //Wait for conversion to complete (become 1)
        label11
  	BTFSS gbl_pir1,6
  	GOTO	label11

        
;//Store ADC value in global variable 'batt'
        MAKESHORT(batt, adresl, adresh);
  	BSF STATUS, RP0
  	MOVF gbl_adresl, W
 	BCF STATUS, RP0
 	MOVWF gbl_batt
 	MOVF gbl_adresh, W
  	MOVWF gbl_batt+D'1'


 	RETURN


;//-----------------------------------------------------------------------------

void display_volts()                //Function to display results via LEDs


        u8 i;                        //Counter

;//Flash LED1 once for each 0.1v above 10.0
;//Code for first 'step' shown nicely below (all other steps closer together to save space)        
        if (batt>=656 && batt<662)                //If battery voltage is between 10.0 and 10.1v
 	MOVLW 0x02
 	BCF STATUS, RP0
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label13
	MOVLW 0x90
	SUBWF gbl_batt, W
    label13
	BTFSS STATUS,C
	GOTO	label17
 	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
 	GOTO	label14
  	MOVLW 0x96
  	SUBWF gbl_batt, W
        label14
  	BTFSC STATUS,C
  	GOTO	label17
        label17


                for(i=0;i<1;i++)
  	CLRF display_vo_00014_1_i
        label15
  	MOVLW 0x01
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
 	GOTO	label16
 	INCF display_vo_00014_1_i, F
  	GOTO	label15
        label16


                        led1(1); delay_ms(250);        //Flash LED1 once for each 0.1v
  	BSF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000

                        led1(0);
  	BCF led1_00000_arg_state,1
  	CALL led1_00000


                delay_s(1);                                        //Pause between cycles (longer when LED flashes once only)
  	MOVLW 0x01
  	MOVWF delay_s_00000_arg_del
  	CALL delay_s_00000


        else if (batt>=662 && batt<669) {for(i=0;i<2;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label18
  	MOVLW 0x96
  	SUBWF gbl_batt, W
        label18
  	BTFSS STATUS,C
  	GOTO	label22
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label19
  	MOVLW 0x9D
  	SUBWF gbl_batt, W
        label19
  	BTFSC STATUS,C
  	GOTO	label22
  	CLRF display_vo_00014_1_i
        label20
  	MOVLW 0x02
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label21
  	BSF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label20
        label21
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label22

        else if (batt>=669 && batt<675) {for(i=0;i<3;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label23
  	MOVLW 0x9D
  	SUBWF gbl_batt, W
        label23
  	BTFSS STATUS,C
  	GOTO	label27
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label24
  	MOVLW 0xA3
  	SUBWF gbl_batt, W
        label24
  	BTFSC STATUS,C
  	GOTO	label27
  	CLRF display_vo_00014_1_i
        label25
  	MOVLW 0x03
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label26
  	BSF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label25
        label26
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label27

        else if (batt>=675 && batt<682) {for(i=0;i<4;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label28
  	MOVLW 0xA3
  	SUBWF gbl_batt, W
        label28
  	BTFSS STATUS,C
  	GOTO	label32
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label29
  	MOVLW 0xAA
  	SUBWF gbl_batt, W
        label29
  	BTFSC STATUS,C
  	GOTO	label32
  	CLRF display_vo_00014_1_i
        label30
  	MOVLW 0x04
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label31
  	BSF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label30
        label31
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label32

        else if (batt>=682 && batt<688) {for(i=0;i<5;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label33
  	MOVLW 0xAA
  	SUBWF gbl_batt, W
        label33
  	BTFSS STATUS,C
  	GOTO	label37
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
  	GOTO	label34
  	MOVLW 0xB0
  	SUBWF gbl_batt, W
        label34
  	BTFSC STATUS,C
 	GOTO	label37
  	CLRF display_vo_00014_1_i
        label35
  	MOVLW 0x05
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label36
 	BSF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	BCF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label35
        label36
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
        label37

        else if (batt>=688 && batt<695) {for(i=0;i<6;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
 	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
  	GOTO	label38
  	MOVLW 0xB0
 	SUBWF gbl_batt, W
        label38
  	BTFSS STATUS,C
 	GOTO	label42
 	MOVLW 0x02
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label39
 	MOVLW 0xB7
  	SUBWF gbl_batt, W5D        
		label39
  	BTFSC STATUS,C
  	GOTO	label42
  	CLRF display_vo_00014_1_i
        label40
  	MOVLW 0x06
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label41
  	BSF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led1_00000_arg_state,1
  	CALL led1_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label40
       label41
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
       label42

        else if (batt>=695 && batt<701) {for(i=0;i<7;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label43
  	MOVLW 0xB7
  	SUBWF gbl_batt, W
        label43
  	BTFSS STATUS,C
  	GOTO	label47
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label44
  	MOVLW 0xBD
  	SUBWF gbl_batt, W
        label44
  	BTFSC STATUS,C
  	GOTO	label47
  	CLRF display_vo_00014_1_i
        label45
  	MOVLW 0x07
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label46
 	BSF led1_00000_arg_state,1
 	CALL led1_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led1_00000_arg_state,1
  	CALL led1_00000
 	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
	GOTO	label45
        label46
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
     label47
        else if (batt>=701 && batt<708) {for(i=0;i<8;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
	GOTO	label48
	MOVLW 0xBD
	SUBWF gbl_batt, W
        label48
  	BTFSS STATUS,C
  	GOTO	label52
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
	GOTO	label49
 	MOVLW 0xC4
 	SUBWF gbl_batt, W
        label49
 	BTFSC STATUS,C
	GOTO	label52
 	CLRF display_vo_00014_1_i
       label50
  	MOVLW 0x08
  	SUBWF display_vo_00014_1_i, W
	BTFSC STATUS,C
	GOTO	label51
	BSF led1_00000_arg_state,1
  	CALL led1_00000
	MOVLW 0xFA
	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led1_00000_arg_state,1
	CALL led1_00000
	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
 	GOTO	label50
        label51
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label52

        else if (batt>=708 && batt<715) {for(i=0;i<9;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label53
  	MOVLW 0xC4
 	SUBWF gbl_batt, W
        label53
	BTFSS STATUS,C
	GOTO	label57
 	MOVLW 0x02
	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
 	GOTO	label54
  	MOVLW 0xCB
  	SUBWF gbl_batt, W
        label54
  	BTFSC STATUS,C
 	GOTO	label57
  	CLRF display_vo_00014_1_i
        label55
  	MOVLW 0x09
  	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
 	GOTO	label56
  	BSF led1_00000_arg_state,1
	CALL led1_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led1_00000_arg_state,1
 	CALL led1_00000
	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
 	GOTO	label55
        label56
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label57

        else if (batt>=715 && batt<721) {for(i=0;i<10;i++) {led1(1); delay_ms(250); led1(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x02
	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label58
 	MOVLW 0xCB
 	SUBWF gbl_batt, W
      label58
  	BTFSS STATUS,C
  	GOTO	label62
  	MOVLW 0x02
	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
 	GOTO	label59
  	MOVLW 0xD1
 	SUBWF gbl_batt, W
        label59
  	BTFSC STATUS,C
 	GOTO	label62
 	CLRF display_vo_00014_1_i
        label60
 	MOVLW 0x0A
	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
 	GOTO	label61
 	BSF led1_00000_arg_state,1
  	CALL led1_00000
 	MOVLW 0xFA
	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led1_00000_arg_state,1
  	CALL led1_00000
	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
 	GOTO	label60
      label61
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label62


;//11.0 - 12.0        
        else if (batt>=721 && batt<728) {led2(1); delay_ms(250); led2(0); delay_s(1);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label63
 	MOVLW 0xD1
  	SUBWF gbl_batt, W
        label63
 	BTFSS STATUS,C
  	GOTO	label65
 	MOVLW 0x02
	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
	GOTO	label64
  	MOVLW 0xD8
 	SUBWF gbl_batt, W
        label64
 	BTFSC STATUS,C
	GOTO	label65
 	BSF led2_00000_arg_state,1
 	CALL led2_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0x01
 	MOVWF delay_s_00000_arg_del
  	CALL delay_s_00000
        label65

        else if (batt>=728 && batt<734) {for(i=0;i<2;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
 	GOTO	label66
	MOVLW 0xD8
 	SUBWF gbl_batt, W
        label66
	BTFSS STATUS,C
  	GOTO	label70
	MOVLW 0x02
	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
	GOTO	label67
	MOVLW 0xDE
	SUBWF gbl_batt, W
        label67
 	BTFSC STATUS,C
 	GOTO	label70
  	CLRF display_vo_00014_1_i
        label68
  	MOVLW 0x02
	SUBWF display_vo_00014_1_i, W
	BTFSC STATUS,C
  	GOTO	label69
  	BSF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label68
        label69
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label70

        else if (batt>=734 && batt<741) {for(i=0;i<3;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
	GOTO	label71
 	MOVLW 0xDE
  	SUBWF gbl_batt, W
        label71
  	BTFSS STATUS,C
  	GOTO	label75
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label72
  	MOVLW 0xE5
  	SUBWF gbl_batt, W
        label72
  	BTFSC STATUS,C
  	GOTO	label75
  	CLRF display_vo_00014_1_i
        label73
  	MOVLW 0x03
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label74
  	BSF led2_00000_arg_state,1
 	CALL led2_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
	MOVLW 0x96
	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
 	GOTO	label73
      label74
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label75

        else if (batt>=741 && batt<747) {for(i=0;i<4;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label76
  	MOVLW 0xE5
 	SUBWF gbl_batt, W
        label76
  	BTFSS STATUS,C
 	GOTO	label80
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
 	GOTO	label77
  	MOVLW 0xEB
  	SUBWF gbl_batt, W
        label77
  	BTFSC STATUS,C
  	GOTO	label80
  	CLRF display_vo_00014_1_i
        label78
  	MOVLW 0x04
 	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label79
 	BSF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
  	GOTO	label78
        label79
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label80
        else if (batt>=747 && batt<754) {for(i=0;i<5;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label81
  	MOVLW 0xEB
  	SUBWF gbl_batt, W
        label81
  	BTFSS STATUS,C
 	GOTO	label85
 	MOVLW 0x02
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label82
  	MOVLW 0xF2
  	SUBWF gbl_batt, W
        label82
  	BTFSC STATUS,C
  	GOTO	label85
 	CLRF display_vo_00014_1_i
        label83
	MOVLW 0x05
 	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
 	GOTO	label84
 	BSF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led2_00000_arg_state,1
 	CALL led2_00000
  	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
 	GOTO	label83
        label84
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label85

        else if (batt>=754 && batt<760) {for(i=0;i<6;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x02
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label86
  	MOVLW 0xF2
  	SUBWF gbl_batt, W
        label86
  	BTFSS STATUS,C
  	GOTO	label90
	MOVLW 0x02
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
 	GOTO	label87
  	MOVLW 0xF8
  	SUBWF gbl_batt, W
        label87
  	BTFSC STATUS,C
  	GOTO	label90
  	CLRF display_vo_00014_1_i
        label88
  	MOVLW 0x06
 	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
 	GOTO	label89
	BSF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0xFA
	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led2_00000_arg_state,1
	CALL led2_00000
 	MOVLW 0x96
	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label88
        label89
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label90

        else if (batt>=760 && batt<767) {for(i=0;i<7;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x02
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label91
	MOVLW 0xF8
 	SUBWF gbl_batt, W
        label91
  	BTFSS STATUS,C
  	GOTO	label95
 	MOVLW 0x02
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label92
  	MOVLW 0xFF
  	SUBWF gbl_batt, W
        label92
  	BTFSC STATUS,C
  	GOTO	label95
	CLRF display_vo_00014_1_i
        label93
 	MOVLW 0x07
 	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
	GOTO	label94
 	BSF led2_00000_arg_state,1
	CALL led2_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	BCF led2_00000_arg_state,1
 	CALL led2_00000
 	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
 	GOTO	label93
        label94
	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label95

        else if (batt>=767 && batt<774) {for(i=0;i<8;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x02
  	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
  	GOTO	label96
 	MOVLW 0xFF
	SUBWF gbl_batt, W
        label96
  	BTFSS STATUS,C
  	GOTO	label100
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label97
  	MOVLW 0x06
  	SUBWF gbl_batt, W
        label97
  	BTFSC STATUS,C
  	GOTO	label100
  	CLRF display_vo_00014_1_i
        label98
  	MOVLW 0x08
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label99
 	BSF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
 	GOTO	label98
        label99
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label100

        else if (batt>=774 && batt<780) {for(i=0;i<9;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label101
 	MOVLW 0x06
 	SUBWF gbl_batt, W
        label101
 	BTFSS STATUS,C
  	GOTO	label105
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label102
  	MOVLW 0x0C
  	SUBWF gbl_batt, W
        label102
  	BTFSC STATUS,C
  	GOTO	label105
 	CLRF display_vo_00014_1_i
        label103
  	MOVLW 0x09
 	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
  	GOTO	label104
  	BSF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label103
        label104
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label105

        else if (batt>=780 && batt<787) {for(i=0;i<10;i++) {led2(1); delay_ms(250); led2(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label106
  	MOVLW 0x0C
  	SUBWF gbl_batt, W
        label106
  	BTFSS STATUS,C
 	GOTO	label110
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label107
  	MOVLW 0x13
  	SUBWF gbl_batt, W
        label107
 	BTFSC STATUS,C
  	GOTO	label110
  	CLRF display_vo_00014_1_i
        label108
  	MOVLW 0x0A
 	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
 	GOTO	label109
  	BSF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
  	GOTO	label108
        label109
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label110

        
;//12.0 - 13.0
        else if (batt>=787 && batt<793) {led3(1); delay_ms(250); led3(0); delay_s(1);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label111
  	MOVLW 0x13
 	SUBWF gbl_batt, W
        label111
 	BTFSS STATUS,C
  	GOTO	label113
 	MOVLW 0x03
	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label112
  	MOVLW 0x19
  	SUBWF gbl_batt, W
        label112
 	BTFSC STATUS,C
  	GOTO	label113
  	BSF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led3_00000_arg_state,1
 	CALL led3_00000
  	MOVLW 0x01
  	MOVWF delay_s_00000_arg_del
  	CALL delay_s_00000
        label113

        else if (batt>=793 && batt<800) {for(i=0;i<2;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label114
  	MOVLW 0x19
	SUBWF gbl_batt, W
        label114
 	BTFSS STATUS,C
	GOTO	label118
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label115
 	MOVLW 0x20
  	SUBWF gbl_batt, W
        label115
 	BTFSC STATUS,C
  	GOTO	label118
 	CLRF display_vo_00014_1_i
        label116
 	MOVLW 0x02
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label117
  	BSF led3_00000_arg_state,1
 	CALL led3_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label116
        label117
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label118

        else if (batt>=800 && batt<806) {for(i=0;i<3;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label119
  	MOVLW 0x20
  	SUBWF gbl_batt, W
        label119
 	BTFSS STATUS,C
  	GOTO	label123
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label120
  	MOVLW 0x26
  	SUBWF gbl_batt, W
        label120
 	BTFSC STATUS,C
  	GOTO	label123
  	CLRF display_vo_00014_1_i
        label121
  	MOVLW 0x03
 	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label122
  	BSF led3_00000_arg_state,1
  	CALL led3_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led3_00000_arg_state,1
  	CALL led3_00000
 	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
 	GOTO	label121
        label122
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
      label123

        else if (batt>=806 && batt<813) {for(i=0;i<4;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
	GOTO	label124
	MOVLW 0x26
	SUBWF gbl_batt, W
      label124
 	BTFSS STATUS,C
	GOTO	label128
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label125
  	MOVLW 0x2D
 	SUBWF gbl_batt, W
       label125
  	BTFSC STATUS,C
  	GOTO	label128
  	CLRF display_vo_00014_1_i
        label126
  	MOVLW 0x04
  	SUBWF display_vo_00014_1_i, W
	BTFSC STATUS,C
  	GOTO	label127
 	BSF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led3_00000_arg_state,1
 	CALL led3_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label126
        label127
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label128

        else if (batt>=813 && batt<819) {for(i=0;i<5;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label129
	MOVLW 0x2D
  	SUBWF gbl_batt, W
        label129
  	BTFSS STATUS,C
 	GOTO	label133
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label130
 	MOVLW 0x33
  	SUBWF gbl_batt, W
        label130
 	BTFSC STATUS,C
  	GOTO	label133
  	CLRF display_vo_00014_1_i
        label131
  	MOVLW 0x05
 	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
 	GOTO	label132
  	BSF led3_00000_arg_state,1
	CALL led3_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led3_00000_arg_state,1
	CALL led3_00000
 	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
 	GOTO	label131
       label132
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label133

        else if (batt>=819 && batt<826) {for(i=0;i<6;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label134
 	MOVLW 0x33
 	SUBWF gbl_batt, W
        label134
  	BTFSS STATUS,C
 	GOTO	label138
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label135
  	MOVLW 0x3A
 	SUBWF gbl_batt, W
        label135
  	BTFSC STATUS,C
  	GOTO	label138
 	CLRF display_vo_00014_1_i
        label136
  	MOVLW 0x06
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label137
  	BSF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
 	GOTO	label136
        label137
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label138

        else if (batt>=826 && batt<833) {for(i=0;i<7;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label139
 	MOVLW 0x3A
  	SUBWF gbl_batt, W
        label139
  	BTFSS STATUS,C
  	GOTO	label143
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
 	GOTO	label140
 	MOVLW 0x41
  	SUBWF gbl_batt, W
        label140
 	BTFSC STATUS,C
	GOTO	label143
	CLRF display_vo_00014_1_i
        label141
  	MOVLW 0x07
 	SUBWF display_vo_00014_1_i, W
	BTFSC STATUS,C
  	GOTO	label142
  	BSF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	BCF led3_00000_arg_state,1
 	CALL led3_00000
 	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
  	GOTO	label141
       label142
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
       label143

        else if (batt>=833 && batt<839) {for(i=0;i<8;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label144
	MOVLW 0x41
  	SUBWF gbl_batt, W
        label144
  	BTFSS STATUS,C
 	GOTO	label148
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
	GOTO	label145
 	MOVLW 0x47
  	SUBWF gbl_batt, W
        label145
 	BTFSC STATUS,C
 	GOTO	label148
	CLRF display_vo_00014_1_i
        label146
 	MOVLW 0x08
	SUBWF display_vo_00014_1_i, W
	BTFSC STATUS,C
 	GOTO	label147
	BSF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
  	GOTO	label146
        label147
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label148

        else if (batt>=839 && batt<846) {for(i=0;i<9;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label149
  	MOVLW 0x47
  	SUBWF gbl_batt, W
        label149
  	BTFSS STATUS,C
  	GOTO	label153
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label150
  	MOVLW 0x4E
  	SUBWF gbl_batt, W
        label150
 	BTFSC STATUS,C
  	GOTO	label153
  	CLRF display_vo_00014_1_i
        label151
  	MOVLW 0x09
 	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label152
	BSF led3_00000_arg_state,1
 	CALL led3_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label151
        label152
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label153

        else if (batt>=846 && batt<852) {for(i=0;i<10;i++) {led3(1); delay_ms(250); led3(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label154
 	MOVLW 0x4E
  	SUBWF gbl_batt, W
        label154
  	BTFSS STATUS,C
 	GOTO	label158
 	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
	GOTO	label155
 	MOVLW 0x54
 	SUBWF gbl_batt, W
        label155
 	BTFSC STATUS,C
 	GOTO	label158
  	CLRF display_vo_00014_1_i
        label156
  	MOVLW 0x0A
  	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
 	GOTO	label157
	BSF led3_00000_arg_state,1
	CALL led3_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led3_00000_arg_state,1
 	CALL led3_00000
	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
  	GOTO	label156
        label157
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label158

        
;//13.0 - 14.0
        else if (batt>=852 && batt<859) {led4(1); delay_ms(250); led4(0); delay_s(1);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label159
 	MOVLW 0x54
  	SUBWF gbl_batt, W
        label159
 	BTFSS STATUS,C
  	GOTO	label161
	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label160
 	MOVLW 0x5B
 	SUBWF gbl_batt, W
        label160
  	BTFSC STATUS,C
  	GOTO	label161
  	BSF led4_00000_arg_state,1
 	CALL led4_00000
	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led4_00000_arg_state,1
 	CALL led4_00000
 	MOVLW 0x01
	MOVWF delay_s_00000_arg_del
 	CALL delay_s_00000
        label161

        else if (batt>=859 && batt<865) {for(i=0;i<2;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
 	GOTO	label162
 	MOVLW 0x5B
 	SUBWF gbl_batt, W
        label162
  	BTFSS STATUS,C
  	GOTO	label166
 	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
 	GOTO	label163
 	MOVLW 0x61
  	SUBWF gbl_batt, W
        label163
 	BTFSC STATUS,C
 	GOTO	label166
 	CLRF display_vo_00014_1_i
        label164
	MOVLW 0x02
 	SUBWF display_vo_00014_1_i, W
	BTFSC STATUS,C
  	GOTO	label165
  	BSF led4_00000_arg_state,1
  	CALL led4_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led4_00000_arg_state,1
 	CALL led4_00000
  	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label164
        label165
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label166

        else if (batt>=865 && batt<872) {for(i=0;i<3;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label167
 	MOVLW 0x61
 	SUBWF gbl_batt, W
       label167
  	BTFSS STATUS,C
  	GOTO	label171
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label168
 	MOVLW 0x68
  	SUBWF gbl_batt, W
        label168
  	BTFSC STATUS,C
 	GOTO	label171
 	CLRF display_vo_00014_1_i
     label169
  	MOVLW 0x03
  	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
  	GOTO	label170
	BSF led4_00000_arg_state,1
  	CALL led4_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	BCF led4_00000_arg_state,1
	CALL led4_00000
	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
 	GOTO	label169
        label170
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label171

        else if (batt>=872 && batt<878) {for(i=0;i<4;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label172
  	MOVLW 0x68
  	SUBWF gbl_batt, W
        label172
  	BTFSS STATUS,C
  	GOTO	label176
 	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label173
 	MOVLW 0x6E
  	SUBWF gbl_batt, W
        label173
 	BTFSC STATUS,C
  	GOTO	label176
  	CLRF display_vo_00014_1_i
        label174
 	MOVLW 0x04
 	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label175
  	BSF led4_00000_arg_state,1
  	CALL led4_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
  	BCF led4_00000_arg_state,1
	CALL led4_00000
	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
 	GOTO	label174
        label175
  	MOVLW 0xFA
	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label176

        else if (batt>=878 && batt<885) {for(i=0;i<5;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label177
  	MOVLW 0x6E
  	SUBWF gbl_batt, W
        label177
 	BTFSS STATUS,C
  	GOTO	label181
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label178
 	MOVLW 0x75
  	SUBWF gbl_batt, W
        label178
  	BTFSC STATUS,C
  	GOTO	label181
  	CLRF display_vo_00014_1_i
        label179
  	MOVLW 0x05
  	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
  	GOTO	label180
  	BSF led4_00000_arg_state,1
 	CALL led4_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
	BCF led4_00000_arg_state,1
  	CALL led4_00000
 	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
  	GOTO	label179
        label180
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label181

        else if (batt>=885 && batt<892) {for(i=0;i<6;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
	GOTO	label182
	MOVLW 0x75
	SUBWF gbl_batt, W
        label182
 	BTFSS STATUS,C
	GOTO	label186
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
  	GOTO	label183
 	MOVLW 0x7C
  	SUBWF gbl_batt, W
        label183
	BTFSC STATUS,C
  	GOTO	label186
  	CLRF display_vo_00014_1_i
        label184
 	MOVLW 0x06
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
 	GOTO	label185
	BSF led4_00000_arg_state,1
  	CALL led4_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led4_00000_arg_state,1
 	CALL led4_00000
 	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	INCF display_vo_00014_1_i, F
  	GOTO	label184
        label185
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label186

        else if (batt>=892 && batt<898) {for(i=0;i<7;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
	GOTO	label187
  	MOVLW 0x7C
 	SUBWF gbl_batt, W
        label187
 	BTFSS STATUS,C
  	GOTO	label191
	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label188
  	MOVLW 0x82
  	SUBWF gbl_batt, W
        label188
 	BTFSC STATUS,C
 	GOTO	label191
	CLRF display_vo_00014_1_i
        label189
	MOVLW 0x07
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
 	GOTO	label190
 	BSF led4_00000_arg_state,1
 	CALL led4_00000
	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	BCF led4_00000_arg_state,1
  	CALL led4_00000
  	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
 	GOTO	label189
        label190
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
	MOVLW 0xFA
	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
        label191

        else if (batt>=898 && batt<905) {for(i=0;i<8;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
	BTFSS STATUS,Z
 	GOTO	label192
 	MOVLW 0x82
	SUBWF gbl_batt, W
        label192
 	BTFSS STATUS,C
 	GOTO	label196
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label193
	MOVLW 0x89
  	SUBWF gbl_batt, W
        label193
  	BTFSC STATUS,C
 	GOTO	label196
 	CLRF display_vo_00014_1_i
        label194
  	MOVLW 0x08
 	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
	GOTO	label195
 	BSF led4_00000_arg_state,1
 	CALL led4_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led4_00000_arg_state,1
	CALL led4_00000
 	MOVLW 0x96
	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
 	GOTO	label194
        label195
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label196

        else if (batt>=905 && batt<911) {for(i=0;i<9;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label197
 	MOVLW 0x89
	SUBWF gbl_batt, W
        label197
 	BTFSS STATUS,C
 	GOTO	label201
  	MOVLW 0x03
  	SUBWF gbl_batt+D'1', W
  	BTFSS STATUS,Z
  	GOTO	label198
  	MOVLW 0x8F
  	SUBWF gbl_batt, W
        label198
  	BTFSC STATUS,C
  	GOTO	label201
 	CLRF display_vo_00014_1_i
        label199
	MOVLW 0x09
  	SUBWF display_vo_00014_1_i, W
 	BTFSC STATUS,C
  	GOTO	label200
 	BSF led4_00000_arg_state,1
 	CALL led4_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led4_00000_arg_state,1
  	CALL led4_00000
 	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	INCF display_vo_00014_1_i, F
 	GOTO	label199
        label200
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
        label201

        else if (batt>=911 && batt<918) {for(i=0;i<10;i++) {led4(1); delay_ms(250); led4(0); delay_ms(150);} delay_ms(250); delay_ms(250);}
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
	GOTO	label202
	MOVLW 0x8F
  	SUBWF gbl_batt, W
        label202
 	BTFSS STATUS,C
	GOTO	label206
 	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label203
	MOVLW 0x96
	SUBWF gbl_batt, W
        label203
 	BTFSC STATUS,C
	GOTO	label206
 	CLRF display_vo_00014_1_i
        label204
  	MOVLW 0x0A
  	SUBWF display_vo_00014_1_i, W
  	BTFSC STATUS,C
  	GOTO	label205
 	BSF led4_00000_arg_state,1
  	CALL led4_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led4_00000_arg_state,1
 	CALL led4_00000
	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
	INCF display_vo_00014_1_i, F
  	GOTO	label204
        label205
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
        label206

        
;//>14.0
        else if (batt>=918) {led5(1); delay_ms(250); led5(0); delay_s(1);}
  	MOVLW 0x03
 	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label207
  	MOVLW 0x96
  	SUBWF gbl_batt, W
        label207
	BTFSS STATUS,C
  	BSF led5_00000_arg_state,1
 	CALL led5_00000
	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	BCF led5_00000_arg_state,1
 	CALL led5_00000
 	MOVLW 0x01
 	MOVWF delay_s_00000_arg_del
 	CALL delay_s_00000


  	RETURN
  	RETURN
  	RETURN
 	RETURN
 	RETURN
 	RETURN
	RETURN
	RETURN
	RETURN
 	RETURN
 	RETURN
	RETURN
 	RETURN
 	RETURN
 	RETURN
 	RETURN
 	RETURN
 	RETURN
  	RETURN
  	RETURN
	RETURN
 	RETURN
 	RETURN
  	RETURN
 	RETURN
 	RETURN
  	RETURN
 	RETURN
 	RETURN
 	RETURN
 	RETURN
	RETURN
	RETURN
 	RETURN
	RETURN
	RETURN
 	RETURN
 	RETURN
 	RETURN
	RETURN
  	RETURN
 	RETURN

                
;//------------------------------------------------------------------------------

;void eeprom_write()                        //Function to write to EEPROM flash memory
{
        intcon.7 = 0;                                //Disable all interrupts while writing to memory
    pir1.7 = 0;                                        //EEIF: Clear this bit which gets set after each write
        
        eecon2 = 0x55;                                //Required before writing to memory
        eecon2 = 0xAA;                                //Required before writing to memory
        eecon1.1 = 1;                                //WR: Writes data eedata to address eeadr

        while(eecon1.1==1);                        //Wait for write to complete (becomes 0 when complete)

        eeadr++;                                        //Increment the address by 1 for next write (8 bit 0-255)
    intcon.7 = 1;                                //Enable interrupts again


;//------------------------------------------------------------------------------

;void led1 (bit state)                //Function to enable or disable LED


        trisio.0 = 1;                        //Set plex1 port as input to disable
 	BSF STATUS, RP0
 	BSF gbl_trisio,0
        trisio.1 = 0;                        //Set plex2 port as output
  	BCF gbl_trisio,1

        trisio.2 = 0;                        //Set plex3 port as output
 	BCF gbl_trisio,2
        
        if (state==1)                        //Switch LED on if so selected
 	BCF STATUS, RP0
 	BTFSS led1_00000_arg_state,1
  	GOTO	label8
        label8


                plex2 = 0;
 	BCF gbl_gpio,1

                plex3 = 1;
 	BSF gbl_gpio,2


        
        else                                        //Switch LED off

              plex2 = 0;
  	BCF gbl_gpio,1

                plex3 = 0;
 	BCF gbl_gpio,2


  	RETURN
  	RETURN


;//------------------------------------------------------------------------------

;void led2 (bit state)                //Function to enable or disable LED


        trisio.0 = 0;
 	BSF STATUS, RP0
 	BCF gbl_trisio,0
        trisio.1 = 0;
  	BCF gbl_trisio,1

        trisio.2 = 1;
 	BSF gbl_trisio,2

        
        if (state==1)                        //Switch LED on if so selected
  	BCF STATUS, RP0
 	BTFSS led2_00000_arg_state,1
 	GOTO	label7
        label7


                plex1 = 0;
 	BCF gbl_gpio,0

                plex2 = 1;
 	BSF gbl_gpio,1

        
        else                                        //Switch LED off
        
                plex1 = 0;
 	BCF gbl_gpio,0

                plex2 = 0;
	BCF gbl_gpio,1

        

 	RETURN
  	RETURN


;//------------------------------------------------------------------------------

;void led3 (bit state)                //Function to enable or disable LED


        trisio.0 = 0;
  	BSF STATUS, RP0
  	BCF gbl_trisio,0
        trisio.1 = 0;
  	BCF gbl_trisio,1

        trisio.2 = 1;
 	BSF gbl_trisio,2

        
        if (state==1)                        //Switch LED on if so selected
 	BCF STATUS, RP0
 	BTFSS led3_00000_arg_state,1
  	GOTO	label6
        label6

        
                plex1 = 1;
  	BSF gbl_gpio,0

                plex2 = 0;
 	BCF gbl_gpio,1

        
        else                                        //Switch LED off
        
                plex1 = 0;
 	BCF gbl_gpio,0

                plex2 = 0;
  	BCF gbl_gpio,1

        

 	RETURN
  	RETURN


;//------------------------------------------------------------------------------

;void led4 (bit state)                //Function to enable or disable LED


        trisio.0 = 1;
  	BSF STATUS, RP0
 	BSF gbl_trisio,0

        trisio.1 = 0;
 	BCF gbl_trisio,1

        trisio.2 = 0;
	BCF gbl_trisio,2

        
        if (state==1)                        //Switch LED on if so selected
  	BCF STATUS, RP0
 	BTFSS led4_00000_arg_state,1
 	GOTO	label5
        label5

        
                plex2 = 1;
  	BSF gbl_gpio,1

                plex3 = 0;
  	BCF gbl_gpio,2

        
        else                                        //Switch LED off
        
                plex2 = 0;
  	BCF gbl_gpio,1

                plex3 = 0;
  	BCF gbl_gpio,2

        

  	RETURN
 	RETURN


;//------------------------------------------------------------------------------

;void led5 (bit state)                //Function to enable or disable LED


        trisio.0 = 0;
 	BSF STATUS, RP0
	BCF gbl_trisio,0

        trisio.1 = 1;
	BSF gbl_trisio,1

        trisio.2 = 0;
 	BCF gbl_trisio,2

        
        if (state==1)                        //Switch LED on if so selected
	BCF STATUS, RP0
	BTFSS led5_00000_arg_state,1
	GOTO	label4
        label4

        
                plex3 = 1;
  	BSF gbl_gpio,2

                plex1 = 0;
  	BCF gbl_gpio,0

        
        else                                        //Switch LED off
        
                plex3 = 0;
 	BCF gbl_gpio,2

                plex1 = 0;
	BCF gbl_gpio,0

        

 	RETURN
	RETURN


;//------------------------------------------------------------------------------

;void led6 (bit state)                //Function to enable or disable LED


        trisio.0 = 0;
	BSF STATUS, RP0
	BCF gbl_trisio,0

        trisio.1 = 1;
  	BSF gbl_trisio,1
        trisio.2 = 0;
  	BCF gbl_trisio,2

        
        if (state==1)                        //Switch LED on if so selected
  	BCF STATUS, RP0
  	BTFSS led6_00000_arg_state,1
  	GOTO	label12
        label12

        
                plex1 = 1;
  	BSF gbl_gpio,0

                plex3 = 0;
 	BCF gbl_gpio,2

        
        else                                        //Switch LED off
        
                plex1 = 0;
 	BCF gbl_gpio,0

                plex3 = 0;
 	BCF gbl_gpio,2

        

  	RETURN
 	RETURN


;//==============================================================================

;void main()


        gpio = 0;                                        //Initialise all ports low on startup
  	BCF STATUS, RP0
 	CLRF gbl_gpio

        
;//Main port settings (1=Input 0=Output)
        trisio.0 = 1;                                //Sets GP0/AN0         (pin7) to INput to disable (plex1)
  	BSF STATUS, RP0
  	BSF gbl_trisio,0

        trisio.1 = 1;                                //Sets GP1/AN1         (pin6) to INput to disable (plex2)
  	BSF gbl_trisio,1

        trisio.2 = 1;                                //sets GP2/AN2         (pin5) to INput to disable (plex3)
	BSF gbl_trisio,2

        trisio.3 = 1;                                //sets GP3                 (pin4) to INput (Push-button)
  	BSF gbl_trisio,3

        trisio.4 = 1;                                //sets GP4/AN3         (pin3) to INput (12v source)
  	BSF gbl_trisio,4

        trisio.5 = 0;                                //Sets GP5                 (pin2) to Output (FET)
  	BCF gbl_trisio,5

    
;//ADC port settings (1=Analog 0=Digital)
        ansel.0 = 0;                                //Sets AN0 (pin7) to digital
  	BCF gbl_ansel,0

        ansel.1 = 0;                                //Sets AN1 (pin6) to digital
  	BCF gbl_ansel,1

    ansel.2 = 0;                                //Sets AN2 (pin5) to digital
  	BCF gbl_ansel,2

    ansel.3 = 1;                                //Sets AN3 (pin3) to analogue (12v battery)
  	BSF gbl_ansel,3

    
    cmcon0 = 0b111;                                //Switches all 3 comparator ports off
 	MOVLW 0x07
 	BCF STATUS, RP0
 	MOVWF gbl_cmcon0

        
;//Static ADC settings
    ansel.4 = 1;                                //ADCS: Set AD Conversion Clock to Fosc/16
  	BSF STATUS, RP0
 	BSF gbl_ansel,4

    ansel.5 = 0;                                //part of above
	BCF gbl_ansel,5

    ansel.6 = 1;                                //part of above
  	BSF gbl_ansel,6

    pie1.6 = 0;                                        //ADC interrupts disabled
  	BCF gbl_pie1,6

    adcon0 = 0b10001101;                //Makes AN3 channel active
  	MOVLW 0x8D
  	BCF STATUS, RP0
  	MOVWF gbl_adcon0

            
;//Static Interrupt settings
    intcon.7 = 1;                                //GIE: Enable interrupts globally
  	BSF gbl_intcon,7

    intcon.3 = 1;                                //GPIE: Enable GPIO interrupts
  	BSF gbl_intcon,3

    ioc.3 = 1;                                        //Enable GP3 (pin4) only
  	BSF STATUS, RP0
  	BSF gbl_ioc,3

;/*
;//Static EEPROM data logging settings
    eecon1.7 = 0;                                //EEPGD: Access data memory
    eecon1.3 = 0;                                //WRERR: clear on startup in case previously set
        eecon1.2 = 1;                                //WREN: enable writing to memory
;*/
;//Flash LED's on startup
        led1(1); delay_ms(150); led1(0); delay_ms(50);
  	BCF STATUS, RP0
  	BSF led1_00000_arg_state,1
 	CALL led1_00000
  	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	BCF led1_00000_arg_state,1
	CALL led1_00000
  	MOVLW 0x32
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000

        led2(1); delay_ms(150); led2(0); delay_ms(50);
 	BSF led2_00000_arg_state,1
 	CALL led2_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led2_00000_arg_state,1
  	CALL led2_00000
  	MOVLW 0x32
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000

        led3(1); delay_ms(150); led3(0); delay_ms(50);
 	BSF led3_00000_arg_state,1
  	CALL led3_00000
  	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
  	BCF led3_00000_arg_state,1
 	CALL led3_00000
 	MOVLW 0x32
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000

        led4(1); delay_ms(150); led4(0); delay_ms(50);
  	BSF led4_00000_arg_state,1
 	CALL led4_00000
 	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	BCF led4_00000_arg_state,1
 	CALL led4_00000
 	MOVLW 0x32
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000

        led5(1); delay_ms(150); led5(0); delay_ms(50);
 	BSF led5_00000_arg_state,1
 	CALL led5_00000
 	MOVLW 0x96
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	BCF led5_00000_arg_state,1
  	CALL led5_00000
 	MOVLW 0x32
	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000

        led6(1); delay_ms(150); led6(0); delay_ms(50);
 	BSF led6_00000_arg_state,1
 	CALL led6_00000
	MOVLW 0x96
 	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
 	BCF led6_00000_arg_state,1
 	CALL led6_00000
  	MOVLW 0x32
  	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000


;//------------------------------------------------------------------------------

        u8        i;                        //Counter
        bit        mode;                //Status indicator
        mode = 1;                //1=Volts above min; 0=volts have been below min
  	BSF main_1_mode,0


        while(1)
        label208
 	GOTO	label208

        
                measure_battery();                //Measure 12v battery voltage
  	CALL measure_ba_00013

                
                if (batt>=656 && mode==1) fet=1; //Activate FET if volts above minimum and not previously too low
 	MOVLW 0x02
	SUBWF gbl_batt+D'1', W
 	BTFSS STATUS,Z
 	GOTO	label209
 	MOVLW 0x90
 	SUBWF gbl_batt, W
        label209
  	BTFSS STATUS,C
 	GOTO	label210
  	BTFSS main_1_mode,0
 	GOTO	label210
 	BSF gbl_gpio,5
        label210

                
                else
  	GOTO	label211
      label211

                
                        fet=0;                                //Otherwise switch FET off
  	BCF gbl_gpio,5
                        mode=0;                                //Set status to prevent FET from being switched on again
  	BCF main_1_mode,0

                        led6(1);                        //Activate warning LED
  	BSF led6_00000_arg_state,1
  	CALL led6_00000

                
                
                if (disp==1)                        //'Display flag' set in interrupt
	BTFSS gbl_disp,0
  	GOTO	label208

                
                        for (i=0; i<3; i++)
	CLRF main_1_i
        label212
  	MOVLW 0x03
 	SUBWF main_1_i, W
  	BTFSC STATUS,C
 	GOTO	label213
	INCF main_1_i, F
 	GOTO	label212
        label213

                        
                                display_volts();//Display voltage three times
 	CALL display_vo_00014

                        
                        disp=0;                                //Reset flag used in interrupt
  	BCF gbl_disp,0

                
                
;                                                        //end while
;                                                        //end main

;                                                        //end main
;////////////////////////////////////////
;// Code with no source :-)
;////////////////////////////////////////
 	GOTO	_startup

 	MOVWF Int1Context
 	SWAPF STATUS, W
	BCF STATUS, RP0
  	MOVWF Int1BContext
 	SWAPF PCLATH, W
	MOVWF Int1BContext+D'1'
 	SWAPF FSR, W
 	MOVWF Int1BContext+D'2'
  	BCF PCLATH,3
 	BCF PCLATH,4
  	GOTO	interrupt
        delay_ms_00000
        ; { delay_ms ; function begin
  	MOVF delay_ms_00000_arg_del, F
  	BTFSS STATUS,Z
  	GOTO	label1
	RETURN
        label1
  	MOVLW 0xF9
        label2
  	ADDLW 0xFF
 	BTFSS STATUS,Z
  	GOTO	label2
 	NOP
  	DECFSZ delay_ms_00000_arg_del, F
 	GOTO	label1
  	RETURN
        ; } delay_ms function end

        delay_s_00000
        ; { delay_s ; function begin
        label3
  	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
  	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
  	CALL delay_ms_00000
 	MOVLW 0xFA
  	MOVWF delay_ms_00000_arg_del
	CALL delay_ms_00000
 	MOVLW 0xFA
 	MOVWF delay_ms_00000_arg_del
 	CALL delay_ms_00000
 	DECFSZ delay_s_00000_arg_del, F
 	GOTO	label3
  	RETURN
        ; } delay_s function end


        _startup
  	BCF PCLATH,3
  	BCF PCLATH,4
  	GOTO	main

 	DW 0x33C4

END

Thanks
 

Okay ignore the above code. Its rubbish.

Hi again

I have reverted to assembly and started learning and trying to piece together my code

I am posting here what I have got so far.
It is nowhere near complete but I will take it a section at a time.

I am attempting to write it so that when the circuit is powered up the switch is read and if it is pressed then it will put a value of 1 into w.
Each subsequent press will increment the value in w by 1(haven't worked out how to do this yet)
Then I want it to go the the increment timer function which reads the value in w and multiplies the 5 minute delay subroutine by that value, so 5 switch presses equals a value of 5 in w and the 5 minute delay will be multiplied by that value up to 30 minutes.

I don't know if this is the easiest way to go about it.
I have also tried to include a debounce based on counting which I found in the gooligum tutorials.

Next on my list of work(once I get all this in the correct order or modified) is to blink my led the number of times to correspond to the timer setting.
Then I need to add some code to enter a programming mode to set the low voltage cutoff(again not worked out yet. Still lots to learn!)

So in a nut shell
1. Is this the easiest way to increment my 5 minute delay?
2. I need to do lots of things at the start and it is doing my head in working out the correct order.
First I want to retain the settings in EEPROM and simply use the last settings for LVC and timer if no switch is pressed. As part of this function I want the led to blink when powered on to indicate how many 5 minute periods it is set to, ie 5 blinks indicates 25 minutes.
Secondly I want to include a programming function for the LVC so if a long press is detected when it is powered on within 1.5 seconds it will enter the adc function(which I have yet to learn and implement)
Thirdly I want to go into the timer setting function by detecting short presses within 1.5 seconds and setting the 5 minute intervals and then after it is set(perhaps by no switch presses) being detected within 1-1.5 seconds, it will flash the number of 5 minute intervals it is set for and then wait for 1 more switch press to start the timers.

Code follows
Code:
;Timer with low voltage cutoff

;Program to monitor a 12v battery
;Uses a FET to drive a load
;Switches the load off when volts reach minimum (10v) 
;Push-button triggers advance in timer incremented by 5 minutes
;This causes led to flash number of 5 minute intervals up to 30 minutes
;Button pushed and held causes led to flash quickly 5 times indicating lvc programming mode has been entered
;once lvc programming mode has been entered voltage is tested through a LM7805 and value is stored in EEPROM for lvc function
;Written for PIC12F683 (8 pin) 
;On startup if button not pushed within 1.5 seconds the led flashes the number of times it is programmed for then waits for button push to activate
;Pushing button again at this time activates the timer
;Programming mode must be entered within the 1.5 secs
;If during led flashing button is pressed again new timer period will be set
;Pin 2(GP5) switches mosfet, Pin 6(GP1) switches mosfet, Pin 3(GP4) reads voltage, Pin 7(GP0) LED output, Pin 5(GP2) Switch input, Pin 1(VDD), Pin 8(VSS)

;//PREPROCESSOR =================================================================

		#include "P12F683.INC"

		errorlevel -302

;//Core configuration options:
		__config _FCMEN_OFF & _IESO_OFF & _PWRTE_OFF & _BOD_OFF & _MCLRE_OFF & _WDT_OFF & _CP_OFF & _CPD_OFF & _INTOSCIO

;//Definitions ====================================================================
		UDATA_SH
Button	EQU		GP2
LED		EQU		GP0
LVC		EQU		GP4
Load	EQU		GP5
B_cnt	res 1					;button debounce
dc1		res 1					;delay counter

		GOTO	Start

;// Constants =====================================================================

;// Subroutines ===================================================================

; Delay = 300 seconds 								
; Clock frequency = 4 MHz 

; Actual delay = 300 seconds = 300000000 cycles 
; Error = 0 % 

   		cblock 0x20
   	d1 
   	d2 
   	d3 
   	d4 
   	count1
   		endc 

DelayW  movwf   count1 			;call DelayW with value in W to multiply timer
								;IE Call DelayW with 5 in w will give a 5 x 5 minute delay			
Delay5							;equalling 25 minutes
    						     ;299999995 cycles 
   		movlw   0x54 
   		movwf   d1 
   		movlw   0xA1 
   		movwf   d2 
   		movlw   0xFD 
   		movwf   d3 
   		movlw   0x02 
   		movwf   d4 
Delay_0 
   		decfsz   d1, f 
   		goto   $+2 
   		decfsz   d2, f 
   		goto   $+2 
   		decfsz   d3, f 
   		goto   $+2 
   		decfsz   d4, f 
   		goto   Delay_0 

						         ;5 cycles 
	   	goto   $+1 
	   	goto   $+1 
	  	nop 
	
    	decfsz   count1   ,f 
    	goto   Delay5 
    	retlw   0x00
		Return



; Timer table =====================================================================
Table
		addwf    PCL,f      
   		retlw   1          		; 5 minute delay    
   		retlw   2          		; 10 minute delay    
   		retlw   3          		; 15 minute delay    
		retlw	4				; 20 minute delay
		retlw	5				; 25 minute delay
		retlw	6				; 30 minute delay	
;**********************************************************************************
; Main Program ====================================================================
Start	 

		BCF STATUS,RP0 			;selects memory Bank 0
		CLRF GPIO
		BSF STATUS,RP0 			;Bank 1 selected
		MOVLW b'00010000' 		;GP4 analog input enable, FOSC/2
		MOVWF ANSEL
		MOVLW b'00010100'		;GP2 & GP4 as inputs, rest as outputs 
		MOVLW	TRISIO

loop
B_dn							;Wait until button down, debounce by counting
		movlw	.13				;max count=10ms/768us=13
		movwf	B_cnt
		clrf	dc1
B_dly	incfsz	dc1,f			;delay 256x3=768us
		goto	B_dly
		btfsc	GPIO,GP2		;if button up GP2 set
		goto	B_dn			;restart count
		decfsz	B_cnt,f			;else repeat until max count
		goto	B_dly


	
	


Increment_timer 	
 		andlw 	b'00011111'		;Implement ANDLW
	   	Call 	Table
	   	Call 	DelayW
		bcf  	GPIO,GP0
		Goto 	Switch_Load

Switch_Load
		



	END

I realize this is not formatted very well. I am right at the start of my learning so please take it easy on me.
I need the basics so if you could pick a small section of the code and help me optimize it, that would be appreciated.

Thanks
Steve
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top