Thursday, November 6, 2008

10-Second Counter

I have made a 10-Second Counter by using a PIC16F627a and a CD4543 BCD to 7-Segment decoder. This circuit and source code are just a demonstration of using MCU to drive an LED 7-Segment Display via CD4543. The 7-Segment displays from 0 to 9 and the number will roll over to 0 again. The interval between change is 1 second. So, this circuit counts 10 seconds between the roll over. I use TIMER1 module and 32.768KHz crystal to make 1 second timebase (see Clock with 32.768KHz Crystal for more info ).

The schematic of the 10-Second counter
Schematic of 10-Second counter
Project setting of MikroC for using internal oscillator of the PIC16f627a.
Setting MikroC for Internal Oscillator

The firmware is written in MikroC and you can find it below.

//PIC16F627A
//4MHz Internal OSC
// One Digit Counter
// 06/11/2008
//Punkky
unsigned short counter;
unsigned short tick;
void interrupt ()
{

        PIR1.TMR1IF = 0;        // clears TMR1IF
        TMR1H = 0x80;
        tick = 1;
}

void main(){
        CMCON = 0x07;   //Digital I/O for PORTA
  TRISA = 0x00;
  PORTA = 0x00;
  TRISB = 0x00;
  PORTB = 0x00
  T1CON = 0x0F
         
  // Prescaler 1:1   external clock 
  PIE1.TMR1IE = 1;  // enable interupt to start the clock 
  INTCON = 0xC0;   // Set GIE, PEIE 
  TMR1L = 0x00
  TMR1H = 0x80
  PCON.OSCF = 1//Internal Clock 4MHz
  //PCON.OSCF = 0; //Internal Clock 48KHz doesn't work well
  counter = 0;
  tick = 0;
  PORTA.F0 = 1// Enable 4345 BCD to 7-Segment
  while(1){
    if(tick){
       tick = 0;
       counter++;
       PORTB = counter;
       if(counter>9){
       counter = 0;
    }
   }
  }
}

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.