Friday, October 31, 2008

Battery backup for Microcontroller projects

My favorite PIC Microcontroller projects are clock projects. All of my clocks are powered by 5V DC wall wart adaptors. In case of power failure, the clocks stop and I have to set time when the electric power is restored. This problem will not happen with the clocks using DS1307 RTC as it provides battery backup capability. However, the clocks without DS1307 or any other RTCs will suffer from power failure. The circuit below is an example of the use of battery backup circuit with PIC16F627A or PIC16F628. The circuit can be used with other Microcontroller chips as a battery backup source. It also provide power failure signal (active low) for further processing.


Battery Backup Microcontroller Circuit

-- Updated 21 Jan 2009 ---
The 1N4148 diodes should be replaced with Shottky diodes, such as, 1N5819 or 1N5822 for lower voltage drops at the diodes.

Wednesday, October 22, 2008

MikroC "Hello World!" LCD example


Just an example of using MikroC to make a simple "Hello World!" PIC Microcontroller LCD project. The MCU is PIC16F877A (of course, it can be PIC16F887). The LCD display word "Hellow World!" on the first line and counting number on the second line. The image above is a screen capture of a simulation. I use the Proteus 7 VSM simulator to simulate my programs.

The source code in MikroC
//Test LCD
char *text = "Hello World!";
char mytext[3];
int i;
void main() {
// pic16f887
// ANSEL = 0x00; //Digital I/O for PORTA
// ANSELH = 0x00; //Digital Input for PORTB

// pic16f877A

CMCON = 0x07; //Set PORTA to Digital input
TRISB = 0; // PORTB is output
TRISA = 0x07; //PORTA as the input/output 0000 0111
i=0;
Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, text); // Print text to LCD, 2nd row
while(1){
while(i<200){
IntToStr(i,mytext);
Lcd_Out(2,1,mytext);
Delay_ms(500);
i++;
}

i=0;
}

}


Tuesday, October 21, 2008

MikroC for PIC Microcontroller Programming

MikroC user interface
As a beginner in PIC Microcontroller, MikroC is my favorite compiler for my Microcontroller projects. I know 'C' already so it's very easy to use MikroC no complex settings involved. MikroC provides a lot of useful and handy libraries for example, LCD interface , UART, I2C, SD card access and many more. Good new, there is a free lite version that can compile code upto 2Kbyte which is enough for beginner projects. The commercial version is also affordable. Of course, I am not selling MikroC :) I just want to share information. Please visit their site for more info: http://www.mikroe.com/

MikroC sample for sending "Hello World!" to LCD

Lcd_Init(&PORTB); // Initialize LCD connected to PORTB
Lcd_Cmd(Lcd_CLEAR); // Clear display
Lcd_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Out(1, 1, "Hello World!");

Laco Black Pilot Watch Limited 50 pcs.

This post is not related to Microcontroller but it is about what I am up to :)
My watch shop http://www.watchkzy.com has collaborated with Laco.de (a long history German watch brand) to produce limited edition watches that really limited. It not limited to 1000 or 100 pieces but there are only 50 pieces in the world !! There are only 50 persons in the world that own this watch. If you have this watch, it might be the only one in your country.
Normally you will see no less than 1000 pieces limited edition from the most watch companies and those watches will be selling at sky rocket prices. I can sell this piece for lower price as I cut all of the marketing cost. Do you know that more than 50% of a watch price is marketing cost?

Check the availibility and price from http://www.watchkzy.com/watch/laco/limited-black-pilot_english.html

Laco Black Pilot's Watch Limited Edition

Please note that the strap in the picture is not comming with the watch.

Sunday, October 19, 2008

ICSP: In-Circuit Serial Programming is great

At the beginning of my PIC journey, when I want to program *.hex file to my PIC microcontroller, I have to remove the PIC from the circuit board and place it on my PIC programmer to program the *.hex file to it and then I remove it from the programmer and put the PIC back to the circuit board. If I want to re-program the PIC, I have to repeat the process again. This process is very painful and it can cause PIC's pins broken.

Soon after I did a lot of that painful processes, I have discovered that my PIC programmer supports ICSP.

ICSP : In Circuit Serial Programming is very useful when I want to program *.hex file to PIC microcontroller while the PIC is on the circuit board. I just plug the ICSP plug to the ICSP jack on the circuit board. The ICSP jack for PIC microcontroller has a circuit like picture below. Now, I put ICSP jack to all of my PIC projects and I can easily upgade their firmware.
ICSP: In-Circuit Serial Prgramming

Thursday, October 16, 2008

Open-Drain RA4 pin on PIC Microcontroller

I had a problem with RA4 pin which I cound not send '1' nor output 'high' to this pin. After some searches, I have found that RA4 pin (pin 3 for PIC16F627a) is "Open-Drain" type output pin. That means it cannot source current and it will be high impedance when assigned logic '1' to it. I cannot set this pin as an output pin by using 'TRISA=0x00'. The solution is attaching a pull up resistor (10K) to the RA4 pin in order to use this pin as an output pin.

RA4 Open Drain PIC16F627a

Wednesday, October 15, 2008

Schematic of 8x8 Led Dot Matrix Clock using PIC16F627A

Schematic of 8x8 Led Dot Matrix Clock using PIC16F627A
The above schematic is 8x8 Led Dot Matrix clock using PIC16F627A (or PIC16F628 which is more expensive but larger memory) and a shift register 74HC595. The PIC is running with 4MHz internal oscillator so pin 15 (RA6) and 16 (RA7) are free. Therefore, the PIC16F627a can drive the 8x8 Led Drive matrix with these 2 free pins (RA6, RA7) and RB0-5, . The Timer1 (TMR1) external clock is generated by the watch crystal 32.768KHz + load capacitors 15pF and fed to RB6 and RB7. The pins are used up!. Method of setting time is similar to the 5x7 Led Dot Matrix Clock.

I have intention to make this with SMD components so the 8x8 Dot Matrix will be the biggest component. The whole clock will be just 20x20mm which is small enough to be a small pocket watch or even a wristwatch. The only problem is the power supply.

Saturday, October 11, 2008

8x8 Led Dot Matrix Clock using PIC16F627A

Led Dot Matrix Clock 8x8 Actually, I have made this long before the 5x7 led dot matrix clock. The clock utilizes a PIC16F627A and a 74HC595 to drive a small 8x8 Led Dot Matrix display (20x20mm). My dream is transforming these clocks to watches that I can ware on my wrist.

8x8 Led Dot Matrix Clock using PIC16F627A

Tuesday, October 7, 2008

Where to buy DS1307 RTC

DS1307
The DS1307 Real Time Clock chip is not so easy to get.

To my knowledge, you can buy the DS1307 from DonTronics

Monday, October 6, 2008

Big 5x7 Led Dot Matrix Clock with new font

Now, I'm so crazy about led dot matrix clocks and led dot matrix watches. Just recently, I have upgraded my small 5x7 Led Dot Matrix Clock with a bigger green 5x7 led dot matrix display and a new font.
For the images below, the time 21:44:37 was displaying on the clock. The clock display is big comparing to a 44mm Panerai (PAM 4).
Big Green 5x7 Led Dot Matrix Clock
Big Green 5x7 Led Dot Matrix Clock
Big Green 5x7 Led Dot Matrix Clock

The code for the new font is showing below:

const unsigned char char2[][4]={
{0x0E,0x11,0x0E,0x00}, //0
{0x09,0x1F,0x01,0x00}, //1
{0x13,0x15,0x09,0x00}, //2
{0x11,0x15,0x0A,0x00}, //3
{0x1C,0x04,0x0F,0x00}, //4
{0x19,0x15,0x12,0x00}, //5
{0x0E,0x15,0x12,0x00}, //6
{0x13,0x14,0x18,0x00}, //7
{0x0A,0x15,0x0A,0x00}, //8
{0x09,0x15,0x0E,0x00}, //9
{0x0A,0x04,0x0A,0x00}, //Comma1
{0x04,0x0A,0x04,0x00} //Comma2
};