SLA Charger/Backup System

JohnInTX

Joined Jun 26, 2012
4,787
Bingo!
Next is to restore the systik using TMR0. Strip out all of the old firmware PWM stuff. I would set the time to 5-10 ms for now using the defines. Wiggle an unused output on each interrupt to confirm the timing. If you set the output when you enter the IRQ service and clear it when you leave you'll also get an idea of how much time is spent in the IRQ service routine. Nice to know.
Once that is working, fix up the beeper on/off control. Then the beeper pattern thing should work. If you don't need patterns you can still have an easy beeper control by passing an ON time to a beepON() function, set a derived timer and have the beeper task turn it off then the timer runs out.
This would be a good time to get the switch debouncing updated and running off the systik, too.
Once all that is going, we'll take a look a the LCD - it will be useful to debug the ADC. You should sketch up a list of displays it needs to show, how often etc. so that we can get an idea the best way to do it. For example, I found in my charger work that I had to shadow the ports due to the ambient noise - that would eliminate the use of MikroC's libraries. Maybe I'm being too paranoid, though. At least we could start with the LCD libs using one of the patches discussed above then port to our own if necessary. We should have a pow-wow with @MMcLaren and decide on the best way to do it.
Nice work!
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Ummm ! Thanks :)

1. TMR0 systik..... I can do tht.
2. 5-10ms using systik.....I can do tht.
3. Wiggle something. Oki doki....need to connect a wire so I can scope the used pin. Will do before hand.
4. Beeper on off....
Q...? How about I set up the switch with a systik debounce...flag the switch and see if it beeps with each switch press..it would be nice.???
5. I can apply beep pattern to the Switches to test...!
6. Switch debounce... taken care off above.
7. Sketch a list of msg's to LCD and how often ....Will do after the above.

You said something about ambient noise. Why would that affect the ADC as it not that critical for me. You did a charger before ? o_O
As for the pow-wow...I am game. :D
 

JohnInTX

Joined Jun 26, 2012
4,787
3) for a quick test, you can output it to one of the LCD data lines, it won't care.
Q) Sure. Then hammer the buttons. Good quick test.
You said something about ambient noise. Why would that affect the ADC as it not that critical for me. You did a charger before ?
'Ambient' is a bad term. Electrical noise from contactors, other things in the building. Consider what happens if you convert right when a spike hits your analog voltage input. The ADC suddenly converts a much larger value and the charger says 'DONE!'. Chargers and the like tend to live in some crappy environments so you have to make the firmware tolerant of that - switch debounce, average ADC readings, shadow output ports and more. And yes, one of my early and still current clients manufactures industrial LA/SLA battery chargers for forklifts, warehouse tugs, mine trains and the like - both stationary and ride-along. I did all of the controls for them starting with timer chips and CMOS logic before the micros. I just got them moved from the old 16C OTP stuff to the very cool 16F1xxx stuff. Assembly language throughout. So.... when I recommend things like shadowing etc., it is to save you from all of things I had to find out the hard way.. But you have the final decision, much as I'd like a site-visit in Maldives it is probably not on the calendar for now.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Hmmm..OK.. You have experience and let's go with that. I did not know you did so many jobs with chargers. :oops:
Lucky to have you around.:)

You know you should take a vacation and see the white sandy beaches and the clear blue seas. :D
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
2 Hrs and I got this part
1. TMR0 systik..... I can do tht.
2. 5-10ms using systik.....I can do tht.
3. Wiggle something. Oki doki....need to connect a wire so I can scope the used pin. Will do before hand.
I decided why not put a LED to indicate if the TMR0 is running as the PIC is working. So below code are the things I added

C:
/*
********** PIC Configuration ************

--------------------------------------------------------------------------------
********** IO Configuration ************

RB3 as a LED out to indicate PIC working.
----------------------------------------------------------*/
// Control bit Assignments.

sbit uPC_OK at RB3_bit;

/******* PROGRAM CONFIGURATION **********/
#define TMR0period_us 150
#define uPC_OKPeriod_ms 2000
#define Toggle_uPC_OK (PORTBimg ^= uPC_OKmask)

// Mask bits
#define uPC_OKmask 0x08                // uPC OK at RB3

/******* CALCULATED CONSTANTS ***********/
#define TMR0reload 256-TMR0period_us   // TMR0 reload value
#define msec5PSset 5000/TMR0period_us  // 5 millisecond
#define Switch_Deb_Tiks 4              // 4*5 = 20ms for Switch debounce
#define uPC_OKTimerSET (uPC_OKPeriod_ms /(5*2))

unsigned char SwitchDebK, msec5PreScaler, uPC_OKTimer_5ms, PORTBimg;


/********  ISR ***************************/
void interrupt(){
    TMR0 += TMR0reload;
    INTCON.T0IF = 0;
//---------Service derived Timer ---------
    if(msec5PreScaler == 0){
       msec5PreScaler = msec5PSset;
        if(uPC_OKTimer_5ms) uPC_OKTimer_5ms--;
    }
    else
       msec5PreScaler--;
 
    PORTB = PORTBimg;
}  // End of IRQ service


/******** Main **************************/
void main(){
    OSCCON = 0x77;
    INTCON = 0;                        // Clear IRQ's
    PIE1 = 0;                          // Clear IRQ's
    PIE2 = 0;                          // Clear IRQ's
    OPTION_REG = 0x88;                 // No pullups TMR0 runs as Tcyc

    ANSEL = 0x0F;                      // RA <0:4> as Analog Inputs
    ANSELH = 0x00;                     // Rest of Analog as Digitla I/O
    CM1CON0 = 0x07;                    // Disable comparator 1
    CM2CON0 = 0x07;                    // Disable comparator 2
 
    PORTA = 0;                         // Clear Ports
    PORTB = 0;                         // Clear Ports
    PORTC = 0;                         // Clear Ports
    TRISA = 0xFF;                      // PortA as Inputs
    PORTBimg = 0xD0;
    TRISB = 0xD0;                      // PortB 'b11010000'
    TRISC = 0x00;                      // PortC as Outputs
// -------- Clear Flags   ----------------------
    SysCheck = 0;                      // Clear Flag bit
    BattChange = 0;                    // Clear Flag bit
    FloatCharge = 0;                   // Clear Flag bit
    ACOK = 0;                          // Clear Flag bit
    ACON = 0;                          // Clear Flag bit
    BattStatus = 0;                    // Clear Battery Status flag
    Backlit = 0;
    CheckBattery = 0;
    uPC_OK = 0;
    Back_lit= 1;
// -------- Fire up Timers  --------------------
    TMR0 = 0;                          // Clear TMR0 Register
    INTCON.T0IF = 0;                   // Clear TMR0 Interrupt flag bit
    INTCON.T0IE = 1;                   // Enable TMR0 Interrupt
    TMR2 = 0;                          // Clear TMR2 Register
    PR2 = 166;                         // PR2 Register is 166 decimal
    T2CON = 0x05;                      // PostSclr = 1:1,TMR2 ON, PreSclr 4
    PIR1.TMR2IF = 0;                   // Clear TMR2 to PR2 interrupt Flag
    PIE1.TMR2IE = 0;                   // TMR2 to PR2 Match interrupt Disable
    CCPR1L = 0x54;                     // PWM MSB bits
    CCP1CON = 0x2F;                    // PWM LSB bits & PWM mode
    INTCON.GIE = 1;                    // Globle Interrupt Enable

    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);

while(1){
//----- Processor Working Toggle LED --------------------------
    if(uPC_OKTimer_5ms == 0){
       uPC_OKTimer_5ms = uPC_OKTimerSET;
       Toggle_uPC_OK;
    }
//--------------------------------------------------------------


}
}
And this is the scope image on RB3

RB3.png
Can you lay this out for me, please
I tried to figure out the TMR0 Interrupt period time but the more I punched the numbers the more confuse I get.



The buzzer is still shouting.
Now thinking of stopping the buzzer.
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
C:
#define Batt_ChangeOpen (PORTA & Batt_ChangeMask)// 1 means open
Above is for active low input.

What would be the case for a active high input switch ?
 

JohnInTX

Joined Jun 26, 2012
4,787
Assuming the mask is something like 0b00010000, you would use
#define Batt_ChangeOpen (Batt_ChangeMask & ~PORTA) // who says there ain't no easy answers!

That squiggle is the binary negation operator - check it out in your C reference. It inverts all of the bits read (making the one you are interested in from active 0->1) then uses the mask to set all of the other bits to 0. Nice!

Edit: just saw your other timer question.. Distracted by that nice scope display I guess..
/******* CALCULATED CONSTANTS ***********/
#define TMR0reload 256-TMR0period_us // TMR0 reload value
#define msec5PSset 5000/TMR0period_us // 5 millisecond
#define Switch_Deb_Tiks 4 // 4*5 = 20ms for Switch debounce
#define uPC_OKTimerSET (uPC_OKPeriod_ms /(5*2)) // should be /5 since that's the prescaler time. Its running at 2X the desired speed (2000ms) because of that, I think.

I'm not sure why we wound up with a define like that. It should be something like:
#define uPC_OKTimerSET (uPC_OKPeriod_ms /sysTIKms) // where sysTIKms is defined as or evaluated to 5. I think I tried something like that but it didn't evaluate correctly and I just jabbed in a constant. Poor discipline on my part.. The whole idea of taking the time to define timings this way is to do just this i.e. change some basic timing parameter and have the compiler recalculate everything for you.. Oh well.

Looks good otherwise though.
Verify that then consider changing the 150us to something more reasonable. The setting would be something that is the shortest time you'd be interested in. 1ms might be good for a start. That will require changing the TMR0's prescaler to 8 and the reload value to 6 (256-250). That is from 1ms / 500ns Tcyc = 2000. 2000/8 = 250. Since the counter counts up to rollover at 0, you set it at 6 and it interrupts 250 counts later (1ms).

This can be automated by some changes in the defines:
#define Tcyc_ns 500 // 8Mhz is 500ns cycle
#define T0PS 8 // prescaler = 8 (you have to change OPTION_REG of course)
#define T0Period_us 1000 // 1ms interrupt period expressed in uSec.
That gives:
#define TMR0_preset (256-( (T0Period_us * 1000) / (Tcyc_ns * T0PS) ) )
If you poke the constants in, it should calculate to 6. Or for now, just set it to 6.


The 5 ms prescaler define changes to something like:
#define msec5PSset 5 // a cheapie
or
#define msec5PSset (5000/T0Period_us) // more flexible

The 5ms prescaler should change automatically from 33(.333) to a more accurate 5 on the dot. Everything below that in the timing chain would work the same.

If you don't want to do all of the defines for now, just poke in the calculated values, but you can see the benefit - especially if you take into account more timer info like its prescaler... It will also pay off as you take your slick sysTIK code from project to project that may have different oscillator speeds or timing requirements.

Good luck.
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I am on it.
I am sorry I forgot to mention something important. :(
I need to have a Maximum of 2 Hr count down period for the float charge timer. Need not be accurate. Float charge timer is activated and count down when battery voltage reaches the required charge current ( measured in ADC ) Just approximation will be OK.
Just asking...will it change a whole lotta code to add that or just a derived timer suffice.
It's all nothing more is needed.

Just the messages is left.

Just a thought. We can use TMR1 for 1sec TIK
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Slowly I think this is making sense. But I cannot get to 1ms.
I change the defines like this
C:
/******* PROGRAM CONFIGURATION & CALCULATED CONSTANTS **********/
#define Tcyc_ns 500 // 8MHz is 500ns cycle
#define TMR0PS 8 // TMR0 prescaler = 8
#define TMR0Period_us 1000 // 1ms Interrupt period in micro sec.
#define TMR0reload (256-((TMR0Period_us * 1000) / (Tcyc_ns * TMR0PS) ))// TMR0 reload value
#define msec5PSset (5000/TMR0Period_us)  // 5 millisecond
#define uPC_OKPeriod_ms 1
#define uPC_OKTimerSET (uPC_OKPeriod_ms)
#define Toggle_uPC_OK (PORTBimg ^= uPC_OKmask)
And

C:
OPTION_REG = 0x82;                 // No pullups TMR0 runs as Prescaler 8
And I am getting this

12MS.png

I cannot get to a 5ms.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
A derived timer will suffice for the 2 hours timer. You do it with additional prescaler bytes chained onto the 5ms timer. When done with updating the 5ms ones bump a seconds prescaler (200 * 5ms). You have a now have a chain of seconds timers. At the end of the seconds chain, add a minutes prescaler (60*sec). When that runs out, it has been one minute. In that chain, decrement the 2 hour timer (120minutes fits into 1 byte). Done.

I'll take a look at your code after I get done scolding the children on another thread.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
A derived timer will suffice for the 2 hours timer. You do it with additional prescaler bytes chained onto the 5ms timer. When done with updating the 5ms ones bump a seconds prescaler (200 * 5ms). You have a now have a chain of seconds timers. At the end of the seconds chain, add a minutes prescaler (60*sec). When that runs out, it has been one minute. In that chain, decrement the 2 hour timer (120minutes fits into 1 byte). Done.
I figured that much but thought I ask for advice.

scolding the children on another thread.
o_O Come again.
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Guess what...? :D

C:
/******* PROGRAM CONFIGURATION & CALCULATED CONSTANTS **********/
#define Tcyc_ns 500 // 8MHz is 500ns cycle
#define TMR0PS 8 // TMR0 prescaler = 8
#define TMR0Period_us 1000 // 1ms Interrupt period in micro sec.
#define TMR0reload (256-((TMR0Period_us * 80) / (Tcyc_ns * TMR0PS) ))// TMR0 reload value
#define msec5PSset (5000/TMR0Period_us)  // 5 millisecond
#define uPC_OKPeriod_ms 1
#define uPC_OKTimerSET (uPC_OKPeriod_ms)
#define Toggle_uPC_OK (PORTBimg ^= uPC_OKmask)
#define Switch_Deb_Tiks 4              // 4*5 = 20ms for Switch debounce


/********  ISR ***************************/
void interrupt(){
    TMR0 += TMR0reload;                // Reload TMR0 to trim Period
    INTCON.T0IF = 0;                   // Clear IRQ flag
//---------Service derived Timers ---------
/*Prescaler counts msec5PSset interrupts to make a 5msec period.
From that, as many timers can be created as desired. Set the timer
to the number of IRQ periods to time. The timer will run to 0 and stop.
Poll the timer, when its 0, time is out. Do something, reload and go.*/
    if(msec5PreScaler == 0){           // Iff prescaler is 0(ran out), then
       msec5PreScaler = msec5PSset;    // Prescaler is set value(reload)
        if(uPC_OKTimer) uPC_OKTimer--;// Iff timer is not zero-decrement
    }
    else                               // else
       msec5PreScaler--;               // decrement prescaler
  
    PORTB = PORTBimg;                  // And Update PORTB
}  // End of IRQ service


OPTION_REG = 0x82;                 // No pullups TMR0 runs as Prescaler 8

while(1){
//----- Processor Working Indicator LED --------------------------
    if(uPC_OKTimer == 0){
       uPC_OKTimer = uPC_OKTimerSET;
       Toggle_uPC_OK;
    }
//--------------------------------------------------------------
And a 1ms on the dot

1ms.png

And if I want 5ms, I only change below define
CSS:
#define uPC_OKPeriod_ms 5
5ms.png
On the dot.

How's that :cool:
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Why do I think my IRQ is at 1Kh? o_O
I am experimenting in toggling another port in IRQ and it is always 1Khz. Even the Led can be set to flash rate 4Hz :confused: but IRQ is 1ms
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Sorry.
I cannot control the buzzer I want.
It is either ON or OFF.

Any suggestions?
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
Sorry for the late reply.
(line 5 post#52)
#define TMR0reload (256-((TMR0Period_us * 80) / (Tcyc_ns * TMR0PS) )) doesn't evaluate to 6 like it should. The one in post #49 does. Why the difference? Anyway, #46 should get you an interrupt every 1msec. That's your systik.
For a test, I would set a bit on PORTB when it interrupts then clear it when you leave. You should get a bunch of spikes at 1ms intervals. Alternatively, You can toggle the line and each 1/2 cycle will be 1ms long for a 500hz frequency.
Can you post your current code?
 
Last edited:

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
I believe I did toggling but it did not help.
I will post the code tonight.

In the mean time I did another code.
I discarded TMR2 and did the buzzer same as the PWM code for led strip one. The TMR0 is doing all the work. I will use TMR1 for the 1sec systik.
That is working nicely. Buzzer on off too. The led toggling and everything.

This one only needs to fix LCD jumbling part.
Plus a little issue as the PORTCimg is writing to port and messing up LCD backlit port. But I think I have the solution and will try tonight
 

Thread Starter

R!f@@

Joined Apr 2, 2009
10,004
Code using CCP1CON

C:
********** PIC Configuration ************

--------------------------------------------------------------------------------
********** IO Configuration ************
RA0 as AN0 - Senses Vbatt      -- Battery Voltage Monitor ADC in.
RA1 as AN1 - Senses Charge_CS  -- Battery Charge Current Monitor ADC in.
RA2 as AN2 - Senses MainPSU_OK -- Main Power Supply 18V to 19.5V Monitor ADC in.
RA3 as AN3 - Senses SubPSU_OK  -- 13.5V PSU Monitor ADC in.
RA4 not used.
RA5 as AN4 - Senses Charger_OK -- Senses the Charger output Monitor ADC in.
RA6 as Digital In - System check Switch - Active high.
RA7 as Digital In - Battery Change Switch - Active high.
RB0 as Digital Out - Active High output - Float Charging Signal.
RB1 as Digital Out - Active High output - Charger Switch on Signal.
RB2 as Digital Output -- LCD Backlit Enable.
RB3 as a LED out to indicate PIC working.
RB4 as Digital In - Senses AC_OK -- Active High Signal.
RB5 as Digital Out - Active High output - AC_ON Signal.
RB6 as PGC for Debugging.
RB7 as PGD for Debugging.
RC0 to LCD RS
RC1 to LCD Enable
RC2 as Digital Output -- Buzzer Output
RC3 to LCD D5
RC4 to LCD D6
RC5 to LCD D7
RC6 to LCD D4
RC7 Not Used
------------------------------------------------------------------------------*/
// ****** LCD Configuration ************
sbit LCD_RS at RC0_bit;
sbit LCD_EN at RC1_bit;
sbit LCD_D4 at RC6_bit;
sbit LCD_D5 at RC3_bit;
sbit LCD_D6 at RC4_bit;
sbit LCD_D7 at RC5_bit;
sbit LCD_RS_Direction at TRISC0_bit;
sbit LCD_EN_Direction at TRISC1_bit;
sbit LCD_D4_Direction at TRISC6_bit;
sbit LCD_D5_Direction at TRISC3_bit;
sbit LCD_D6_Direction at TRISC4_bit;
sbit LCD_D7_Direction at TRISC5_bit;
// End of LCD Connections.

// Control bit Assignments.
sbit Sys_Check at RA6_bit;
sbit Batt_Change at RA7_bit;
sbit Float_Charge at RB0_bit;
sbit Charger_On at RB1_bit;
sbit Back_lit at RB2_bit;
//sbit uPC_OK at RB3_bit;
sbit AC_OK at RB4_bit;
sbit AC_On at RB5_bit;

// Flags for above
bit SysCheck, BattChange, FloatCharge, ACOK, ACON, Backlit;
// Rest of Flags
bit BattStatus, CheckBattery;

// End of Control bit Assignments.

/******* PROGRAM CONFIGURATION & CALCULATED CONSTANTS **********/
#define Tcyc_ns 500                    // 8MHz is 500ns cycle
#define TMR0PS 8                       // TMR0 prescaler = 8
#define TMR0Period_us 1000             // 1ms Interrupt period in micro sec.
#define TMR0reload (256-((TMR0Period_us*80)/(Tcyc_ns * TMR0PS)))// TMR0 reload value
#define msec1PSset (5000 / TMR0Period_us)// 1 millisecond
#define uPC_OKTimerSET 500             // 500ms Flash rate for the uPC OK led
#define msec5PSset 5                 //  5ms
#define Toggle_uPC_OK (PORTBimg ^= uPC_OKmask)// Led Toggle Mask
#define Switch_Deb_Tiks 20             // 20*1 = 20ms for Switch debounce
// Mask bits
#define Sys_CheckMask 0x40             // System Check Sw at RA6
#define Batt_ChangeMask 0x80           // Battery Change Sw at RA7
#define Sys_CheckOpen (PORTA &~ Sys_CheckMask)// 0 means open
#define Batt_ChangeOpen (PORTA &~ Batt_ChangeMask)// 0 means open
#define uPC_OKmask 0x08                // uPC OK Led at RB3

unsigned char SwitchDebK, msec1PreScaler, uPC_OKTimer, PORTBimg;
unsigned char msec5PreScaler, msec5Timer;

/********  ISR ***************************/
void interrupt(){
    TMR0 += TMR0reload;                // Reload TMR0 to trim Period
    INTCON.T0IF = 0;                   // Clear IRQ flag
//---------Service derived Timers ---------
/*Prescaler counts msec1PSset interrupts to make a 1msec period.
From that, as many timers can be created as desired. Set the timer
to the number of IRQ periods to time. The timer will run to 0 and stop.
Poll the timer, when its 0, time is out. Do something, reload and go.*/
//------- 1 milli second Timer  ------------------
    if(msec1PreScaler == 0){           // Iff prescaler is 0(ran out), then
       msec1PreScaler = msec1PSset;    // Prescaler is set value(reload)
        if(uPC_OKTimer) uPC_OKTimer--; // Iff timer is not zero, decrement

    }
    else                               // else
       msec1PreScaler--;               // decrement prescaler
     
   PORTB = PORTBimg;                  // And Update PORTB
//------- 5 milli second Timer  ------------------
    if(msec5PreScaler == 0){           // Iff prescaler is 0(ran out), then
       msec5PreScaler = msec5PSset;    // Prescaler is set value(reload)
        if(msec5Timer) msec5Timer--;   // Iff timer is not zero, decrement

    }
    else                               // else
       msec5PreScaler--;               // decrement prescaler

}  // End of IRQ service
void powerONbeep(){
    CCP1CON = 0x2F;
    delay_ms(50);
    CCP1CON = 0x00;
    delay_ms(50);
    CCP1CON = 0x2F;
    delay_ms(50);
    CCP1CON = 0x00;
}
void Switchbeep(){
    CCP1CON = 0x2F;
    delay_ms(10);
    CCP1CON = 0x00;
}
/******** Main **************************/
void main(){
    OSCCON = 0x77;
    INTCON = 0;                        // Clear IRQ's
    PIE1 = 0;                          // Clear IRQ's
    PIE2 = 0;                          // Clear IRQ's
    OPTION_REG = 0x82;                 // No pullups TMR0 runs as Prescaler 8

    ANSEL = 0x0F;                      // RA <0:4> as Analog Inputs
    ANSELH = 0x00;                     // Rest of Analog as Digitla I/O
    CM1CON0 = 0x07;                    // Disable comparator 1
    CM2CON0 = 0x07;                    // Disable comparator 2
  
    PORTA = 0;                         // Clear Ports
    PORTB = 0;                         // Clear Ports
    PORTC = 0;                         // Clear Ports
    TRISA = 0xFF;                      // PortA as Inputs
    PORTBimg = 0xD0;
    TRISB = 0xD0;                      // PortB 'b11010000'
    TRISC = 0x00;                      // PortC as Outputs
// -------- Clear Flags   ----------------------
    SysCheck = 0;                      // Clear Flag bit
    BattChange = 0;                    // Clear Flag bit
    FloatCharge = 0;                   // Clear Flag bit
    ACOK = 0;                          // Clear Flag bit
    ACON = 0;                          // Clear Flag bit
    BattStatus = 0;                    // Clear Battery Status flag
    Backlit = 0;
    CheckBattery = 0;
// -------- Clear Registers   ----------------------
    SwitchDebK = 0;
    msec1PreScaler = 0;
    msec5PreScaler = 0;
    uPC_OKTimer = 0;
    msec5Timer = 0;
// -------- Fire up Timers  --------------------
    TMR0 = TMR0reload;                 // Load TMR0 Register
    INTCON.T0IF = 0;                   // Clear TMR0 Interrupt flag bit
    INTCON.T0IE = 1;                   // Enable TMR0 Interrupt
    TMR2 = 0;                          // Clear TMR2 Register
    PR2 = 166;                         // PR2 Register is 166 decimal
    T2CON = 0x05;                      // PostSclr = 1:1,TMR2 ON, PreSclr 4
    PIR1.TMR2IF = 0;                   // Clear TMR2 to PR2 interrupt Flag
    PIE1.TMR2IE = 0;                   // TMR2 to PR2 Match interrupt Disable
    CCPR1L = 0x54;                     // PWM MSB bits
    CCP1CON = 0x00;
    INTCON.GIE = 1;                    // Globle Interrupt Enable
    PowerONbeep();
    Lcd_Init();
    Back_lit = 1;
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);

while(1){
//----- Processor Working Indicator LED --------------------------
    if(uPC_OKTimer == 0){
       uPC_OKTimer = uPC_OKTimerSET;
       Toggle_uPC_OK;
    }
//--------------------------------------------------------------

    
    
  }
}
This part is to test the beeping.... it works but u know .....

C:
void powerONbeep(){
    CCP1CON = 0x2F;
    delay_ms(50);
    CCP1CON = 0x00;
    delay_ms(50);
    CCP1CON = 0x2F;
    delay_ms(50);
    CCP1CON = 0x00;
}
void Switchbeep(){
    CCP1CON = 0x2F;
    delay_ms(10);
    CCP1CON = 0x00;
}
 
Top