3 State LEDs - LED On Full, LED On Half and LED OFF

Whilst working on the Voip Desk Phone, I was thinking about what I might want to use the phone's single LED for. I had read about the possibilities of using a LED to detect light level and even communicate. All I wanted to do was indicate the mode the phone was in. I could have just tied it to the power rails, indicating power on, but I connected it to a port and turned it on whenever the handset was picked up. I also wanted to have a way of showing what mode the phone is in, when I get round to implementing the memory dial functions, I will need to be able to tell if the phone is in 'program' mode or not.

The VOIP Desk Phone software, like many other programs, spends most of its time in a loop waiting for something to happen. In this case, watching the keypad and the hook switch to see if a key needs sending to the VOIP software.

Rather than control the port directly, we can use a static Bit flag to indicate the required state of the LED - on or off.

In our 'main loop', we check this Bit Flag and turn the port pin on or off as required. That does not do anything more than give us a virtual LED, we could have just as easily set/reset the port pin. However, if we add another static Bit flag for say 'High/Low' and a counter, things get more interesting.

By adding a counter that is incremented each time through the loop, instead of saying 'if LED = ON port B = 0' we can say something like this:-

LED ON Full, LED ON Half, LED OFF

tickl++; // Bump counter each time we get here.
if (tickl >= 100) tickl = 0 ; // reset every 100 (%)
// they keep counting
if (ledon ==1) // Should LED be on?
{
if (ledhigh ==1) // Should it be on ALL the time?
{
LED = 0;
}
if (ledhigh ==0) // Then see if LED should be on NOW
{
if (tickl <= 50) LED = 0 ; else LED = 1; // led only on 1/2 the time
}
}
if (ledon == 0) LED=1; // LED should be OFF - make it so.
}

The above was used to 'test' the function in the VOIP Desk Phone, I'll include it in the next upload of the code once a few other features have been added. Before that, it should be re-coded to take up less space, but as it is, it is easy to see what it is doing.

Experimenting with Microchip PIC 16F876, 16F628 and other Processors

Introduction
About the PIC Processor
Programing the PIC
Building Blocks
PIC Test Rig

Connecting an LCD
VoipDeskPhone
VoipDeskPhone the Software
VoipDeskPhone3 Changes for use as an Asterisk Console Phone

Cheap PIC Keypad PoundShop Clock / Alarm = Cheap Keypad

3 State LEDs

Add DRAM to a PIC
PIC Links


Google
 
Web picprojects.247n.com

Electronics and Internet Sites at www.247n.com