Showing posts with label MCU. Show all posts
Showing posts with label MCU. Show all posts

Thursday, July 20, 2017

BCD LCD + CC2630

    This is a demo, how to transmit image data to a BCD LCD panel. This system includes:
1) PC base software : It reads image files, then convert it to black-white image format, finally, send the image data to CC2630 control board.
2) CC2630 zigbee coordinator with USB  connector : This device connect to a PC, it will communicate with PC base software by USB virtual COM port.
3) CC2630 zigbee  device : This device is powered by battery, it will receive image data from CC2630 zigbee coordinator, then display the image on the BCD LCD panel.



Monday, July 13, 2009

Radio Clock - Decode JP60 Radio for Japan

Use MCU PIC16F877A + radio clock receiver module, the decoding process is coding by C language.


Friday, October 10, 2008

Make MCU Board - Music Box Module


The music notes is defined by frequency variations,
reference wiki - music note and
C (musical note).

Generally, the calculation is based on A4 music note:
f = [2 ^ (n/12)] × 440 Hz

For easily doing calculation, here we use C-1 as the base level:
There are all 11 levels, each level has 12 music notes
n = (i x 12)(level) + j (jth note)
f = [2 ^ (n/12)] x 8.176 Hz

Calculate all music note's frequencies by python:
# calculate number array
musicNotes = []
for i in range(11):
 row = []
 for j in range(12):
   row.append(8.176 * (2**((i*12+j)*(1.0/12))))
 musicNotes.append(row)

# display frequency table
for i in range(11):
 musicNotes[i]

[8.1760000000000002, 8.6621702594815986, 9.1772497069774346, 9.7229573722622469, 10.301114503940484, 10.913650647694201, 11.562610085962426, 12.250158660543748, 12.978591000891997, 13.75033818222874, 14.567975839030828, 15.434232760971051]
[16.352, 17.324340518963197, 18.354499413954866, 19.445914744524494, 20.602229007880968, 21.827301295388398, 23.125220171924852, 24.500317321087497, 25.957182001783995, 27.50067636445748, 29.135951678061655, 30.868465521942102]
[32.704000000000001, 34.648681037926387, 36.708998827909731, 38.891829489048988, 41.204458015761929, 43.654602590776797, 46.250440343849704, 49.000634642174987, 51.914364003567989, 55.001352728914959, 58.271903356123303, 61.736931043884205]
[65.408000000000001, 69.297362075852774, 73.417997655819462, 77.783658978097975, 82.408916031523859, 87.309205181553594, 92.500880687699407, 98.001269284349974, 103.82872800713598, 110.00270545782992, 116.54380671224661, 123.47386208776841]
[130.816, 138.59472415170555, 146.8359953116389, 155.56731795619595, 164.81783206304772, 174.61841036310716, 185.00176137539881, 196.00253856869995, 207.6574560142719, 220.00541091565984, 233.08761342449321, 246.94772417553673]
[261.63200000000001, 277.1894483034111, 293.67199062327779, 311.1346359123919, 329.63566412609543, 349.23682072621432, 370.00352275079763, 392.00507713739989, 415.3149120285438, 440.01082183131967, 466.17522684898643, 493.89544835107347]
[523.26400000000001, 554.3788966068222, 587.34398124655559, 622.2692718247838, 659.27132825219087, 698.47364145242864, 740.00704550159526, 784.01015427479979, 830.6298240570876, 880.02164366263935, 932.35045369797285, 987.79089670214694]
[1046.528, 1108.7577932136444, 1174.6879624931112, 1244.5385436495676, 1318.5426565043817, 1396.9472829048573, 1480.0140910031905, 1568.0203085495996, 1661.2596481141752, 1760.0432873252787, 1864.7009073959457, 1975.5817934042939]
[2093.056, 2217.5155864272874, 2349.3759249862223, 2489.0770872991352, 2637.0853130087612, 2793.8945658097145, 2960.028182006381, 3136.0406170991969, 3322.5192962283504, 3520.0865746505574, 3729.4018147918891, 3951.1635868085878]
[4186.1120000000001, 4435.0311728545748, 4698.7518499724447, 4978.1541745982704, 5274.1706260175224, 5587.7891316194291, 5920.0563640127621, 6272.0812341983938, 6645.0385924567008, 7040.1731493011148, 7458.8036295837783, 7902.3271736171755]
[8372.2240000000002, 8870.0623457091497, 9397.5036999448894, 9956.3083491965408, 10548.341252035045, 11175.578263238858, 11840.112728025524, 12544.162468396788, 13290.077184913402, 14080.34629860223, 14917.607259167557, 15804.654347234351]

Base on above calculated values, we define const float gMusicNotes[11][12] , all the frequencies are recorded in the array.


The circuit schematic:















The main process:
(Depends on MCU's characters, for PIC16F877A , the compiler is PICC, the memory size of music_cell gSong[] is limited.)
(This program implements delay process, the deviation of sound frequency is obvious; replace by timer process, the sound frequency would be better than delay process)
/*******************************************************************************

  Copyright (c) 2008 Wizign Ltd.
  All Rights Reserved.

  main.c: Main program for demo trigger of speaker

  Version: 1.0.0

  Date: Oct 03, 2008

  Author: YenHung Chen

  E-mail: yhchen@wizign.com

  Revision:
  ---------- -----------------------------------------------------------------
  2008/10/03 Created by YenHung Chen, demo trigger of speaker for both 8051 and PIC

******************************************************************************/
/*******************************************************************************

<>For AT89S52

LCD display:
  There are 8 data pins, which are connected P2.
  The control pins are connected to P1_0, P1_1, and P1_2.

Speaker:
  P3_0


<>For PIC16F877A

LCD display:
  There are 8 data pins, which are connected PORTD
  The control pins are connected to RA0, RA1, and RA2.

Speaker:
  RC0


******************************************************************************/

#include "global.h"
#include "delay.h"
#include "lcd.h"
#include "timer.h"
#include "music.h"

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables

#ifdef MCU_PIC
/*
// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;
*/
#endif

#ifdef MCU_PIC
bank1 static music_cell gSong[] = {
#else   // default is MCU_8051
music_cell gSong[] = {
#endif
  {C4, LA,    1}, {C4, LA, 0.25}, {C4, SO, 0.25}, {C4, LA,  0.5},
  {C4, SO,    1}, {C4, MI,    1}, {C4, SO,  0.5}, {C4, MI,  0.5},
  {C4, MI,  0.5}, {C4, RE,  0.5}, {C4, MI,    2}, {C4, MI,    0},
  {C4, RE,    1}, {C4, RE,  0.5}, {C4, DO,  0.5}, {C4, RE,  0.5},
  {C4, RE,  0.5}, {C4, SO,    1}, {C4, SO,  0.5}, {C4, MI,  0.5},
  {C4, MI,  0.5}, {C4, RE,  0.5}, {C4, MI,    2}, {C4, MI,    0},
  {C4, LA,    1}, {C4, LA,  0.5}, {C4, SO,  0.5}, {C4, LA,  0.5},
  {C4, SO,  0.5}, {C4, MI,    1}, {C4, FA,  0.5}, {C4, FA, 0.25},
  {C4, FA, 0.25}, {C4, MI,  0.5}, {C4, RE,  0.5}, {C4, MI,    2},
  {C4, MI,    0}, {C4, SO,    1}, {C4, SO,  0.5}, {C4, SO,  0.5},
  {C4, SO,  0.5}, {C4, SO,  0.5}, {C4, SI,    1}, {C4, LA,  0.5},
  {C4, LA, 0.25}, {C4, LA, 0.25}, {C4, LA,  0.5}, {C4, SO,  0.5},
  {C4, LA,    2}, {C4, LA,    0}, {C5, DO,    1}, {C5, DO,  0.5},
  {C5, DO,  0.5}, {C4, SI,    1}, {C4, SO,    1}, {C4, LA,  0.5},
  {C4, LA, 0.25}, {C4, LA, 0.25}, {C4, LA,  0.5}, {C4, SO,  0.5},
  {C4, LA,  1.5}, {C4, SO, 0.25}, {C4, MI, 0.25}, {C4, SO,    1},
  {C4, SO, 0.75}, {C4, SO, 0.25}, {C4, SO,  0.5}, {C4, SO,  0.5},
  {C4, SI,    1}, {C4, LA, 0.33}, {C4, LA, 0.33}, {C4, LA, 0.33},
  {C4, LA,  0.5}, {C4, SO,  0.5}, {C4, LA,    2}, {C4, LA,    0}
};

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions

/* Initilize parameters before run the main loop */
void InitParams(void)
{
  LCDInit();
  MusicInit();
}

/* Display message on LCD panel */
void DisplayMusicStatus(char* pMsg)
{
  LCDGoto(0);    // goto 1st line
  LCDPuts("  WIZIGN LTD.  ");

  // Display rotate status
  LCDGoto(0x40);    // goto 2nd line
  LCDPuts(pMsg);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program

void main(void)
{
  int count = 0;
  int direction = 0;  // 0:clockwise, 1:counter clockwise

  // Initilize parameters
  InitParams();

  /* do loop */
  while(1){
      DisplayMusicStatus("Play Music");
      MusicPlay(10, gSong);
  }
}

Wednesday, October 1, 2008

Make MCU Board - DC and Stepper Motor Module


DC motor and stepper motor are generally devices that they are used in automation control domain,
I introduce the control circuit and programming for these 2 type motors, as following:



The circuit schematic:














Main program:
/*******************************************************************************

Copyright (c) 2008 Wizign Ltd.
All Rights Reserved.

main.c: Main program for demo trigger of motors

Version: 1.0.0

Date: Oct 01, 2008

Author: YenHung Chen

E-mail: yhchen@wizign.com

Revision:
---------- -----------------------------------------------------------------
2008/10/01 Created by YenHung Chen, demo trigger of motors for both 8051 and PIC

******************************************************************************/
/*******************************************************************************



<>For AT89S52

LCD display:
There are 8 data pins, which are connected P2.
The control pins are connected to P1_0, P1_1, and P1_2.

Step motor:
P3_0, P3_1, P3_2, P3_3

DC motor:
P3_6, P3_7

<>For PIC16F877A

LCD display:
There are 8 data pins, which are connected PORTD
The control pins are connected to RA0, RA1, and RA2.

Step motor:
RC0, RC1, RC2, RC3

DC motor:
RC6, RC7


******************************************************************************/

#include "global.h"
#include "delay.h"
#include "lcd.h"
#include "motor.h"

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables

#ifdef MCU_PIC

// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;

#endif


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions

/* Initilize parameters before run the main loop */
void InitParams(void)
{

LCDInit();
MotorInit();
}

/* Display message on LCD panel */
void DisplayRotateStatus(char* pMsg)
{
LCDGoto(0);    // goto 1st line
LCDPuts("  WIZIGN LTD.  ");

// Display rotate status
LCDGoto(0x40);    // goto 2nd line
LCDPuts(pMsg);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program

void main(void)
{
int count = 0;
int direction = 0;  // 0:clockwise, 1:counter clockwise

// Initilize parameters
InitParams();

/* do loop */
while(1){
    if(direction == 0){
        DisplayRotateStatus("Clockwise");
        MotorStepRotate(MOTOR_ROTATE_CW, 4);
        MotorDCRotate(MOTOR_ROTATE_CW, 2);
    }else{  // left
        DisplayRotateStatus("C Clockwise");
        MotorStepRotate(MOTOR_ROTATE_CCW, 2);
        MotorDCRotate(MOTOR_ROTATE_CCW, 4);
    }
    count++;
    if(count >= 200){
        count = 0;
        direction = (direction == 0) ? 1 : 0;
    }
}
}

Thursday, September 11, 2008

Make MCU Board - Thermometer (DS1821) module


The reason of choosing DS1821 thermo sensor is that the circuit is very simple, it only need on  IO pin.

Originally, I wrote the test program by SDCC compiler, the test has some problem, the LCD display is work, but the temperature is still display zero?
Then, I did compiling by HI-TECH's PICC, the temperature value is correct.
If you are using PICC, please comment out lines as following:

typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;

Replace pic/pic16f877a.h by htc.h

Circuit schematics is as following:












Main process:
/*******************************************************************************

 Copyright (c) 2008 Wizign Ltd.
 All Rights Reserved.

 main.c: Main program for demo thermometer

 Version: 1.0.0

 Date: Sep 05, 2008

 Author: YenHung Chen

 E-mail: yhchen@wizign.com

 Revision:
 ---------- -----------------------------------------------------------------
 2008/09/05 Created by YenHung Chen, demo thermometer for both 8051 and PIC

******************************************************************************/
/*******************************************************************************

The IO control

<>For AT89S52

LCD display:
There are 8 data pins, which are connected P2.
The control pins are connected to P1_0, P1_1, and P1_2.

DS1821:
P1_7

<>For PIC16F877A

LCD display:
There are 8 data pins, which are connected PORTD
The control pins are connected to RA0, RA1, and RA2.

DS1821:
RA5


******************************************************************************/

#include "global.h"
#include "delay.h"
#include "lcd.h"
#include "thermo.h"

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables

#ifdef MCU_PIC

// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;

#endif


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions

/* Initilize parameters before run the main loop */
void InitParams(void)
{

LCDInit();
ThermoInit();
}

/* Display message on LCD panel */
void DisplayTemperature(void)
{
char tmMsg[16];
int theT;
unsigned char myT;
int hundred;
int tenth;
int ones;

LCDGoto(0); // goto 1st line
LCDPuts("  WIZIGN LTD.  ");

// Convert value to string
myT = ThermoReadTemperature();
if(myT > 127){
   theT = (int)(myT - 0xFF);
}else{
   theT = (int)myT;
}
// start
// it can not display correct format in this block
BLOCK
// end
   hundred = (int)(theT/100);
   tenth = (int)((theT%100)/10);
   ones = theT%10;
   tmMsg[1] = 0x30 + hundred;
   tmMsg[2] = 0x30 + tenth;
   tmMsg[3] = 0x30 + ones;
   tmMsg[4] = 0x20;
   tmMsg[5] = 'C';
   tmMsg[6] = 0x20;
   tmMsg[7] = '\0';

   LCDGoto(0x40); // goto 2nd line
   LCDPuts(tmMsg);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program

void main(void)
{
   // Initilize parameters
 InitParams();

   /* do loop */
   while(1){
    DisplayTemperature();
       // The LCD display and the calculation of time
       // will consume times, so, the delay time is less than 1000 ms.
       DelayMs(900);
   }
}

Wednesday, September 3, 2008

Make MCU Board - EDA Tool - KiCAD


When we design functional MCU module, the circuit schematics is necessarily step for checking IO port.

Except OrCAD and Protel, there are some open source EDA tools.

KiCAD is an open source (GPL) software, we can use KiCAD to design circuit schematics and layout PCB, the author of KiCAD is Jean-Pierre Charras( a research of LIS,Laboratoire des Images et des Signaux, in Frence, he is a electronics and image processing teacher in IUT de Saint Martin d'Hères), he design and coding the KiCAD software.

KiCAD is a composite tools, it includes a project management and 4 specially functional software:

* Eeschema : Design circuit schematics
* Pcbnew : Design PCB
* Gerbview : GERBER viewer
* Cvpcb : For selecting electronic components, while designing circuit.
* Kicad:Project management

KiCAD can use Wings 3D to simulate 3D PCB.

KiCAD does not only run on Windows OS, it can run on Linux, too.

For Fedora Core 9:

# yum install kicad

For Ubuntu 8.04

# apt-get install kicad


The GUI of KiCAD is as following:

Kicad












eeschema












cvpcb











pcbnew












3D simulation












The functions of KiCAD is complete, try it!
If you are software developer, you can download the source code from the official site.

Tuesday, September 2, 2008

Make MCU Board - Digital Clock (LCD Display) module

To calculate time by using delay method, it will causes obvious time deviation, and display the digital value on a LCD panel.

The LCD type is PVC160203PGL01.

The MCU is PIC 16F877A, define IO as following:

RA2 LCD_EN
RA1 LCD_RW
RA0 LCD_RS
PORTD LCD_DATA

If MCU uses AT89S51/52/53, IO definition is:

P1_2 LCD_EN
P1_1 LCD_RW
P1_0 LCD_RS
P2 LCD_DATA

The circuit schematic:



Main program is as following:

/*******************************************************************************

 Copyright (c) 2008 Wizign Ltd.
 All Rights Reserved.

 main.c: Main program for demo LCD display

 Date: Aug 29, 2008

 Author: YenHung Chen

 E-mail: yhchen@wizign.com

 Revision:
 ---------- -----------------------------------------------------------------
 2008/08/29 Created by YenHung Chen, demo LCD display for both 8051 and PIC

******************************************************************************/
/*******************************************************************************



<>For AT89S52

There are 8 data pins, which are connected P2.
The control pins are connected to P1_0, P1_1, and P1_2.


<>For PIC16F877A

There are 8 data pins, which are connected PORTD
The control pins are connected to RA0, RA1, and RA2.


******************************************************************************/

#include "global.h"
#include "delay.h"
#include "lcd.h"

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables

#ifdef MCU_PIC

// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _XT_OSC & _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_OFF;

#endif

int gTmYr;
unsigned char gTmMon;
unsigned char gTmDay;
unsigned char gTmHr;
unsigned char gTmMin;
unsigned char gTmSec;


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions

/* Initialize the begin time */
void InitCurrentTime(int y, unsigned char m, unsigned char d,
                  unsigned char hr, unsigned char min, unsigned char sec){
 gTmYr = y;
 gTmMon = m;
 gTmDay = d;
 gTmHr = hr;
 gTmMin = min;
 gTmSec = sec;
}

/* Calculate the progressing time */
void CalculateTime(void)
{
 gTmSec++;
 if(gTmSec >= 60){
     gTmSec = 0;
     gTmMin++;
     if(gTmMin >= 60){
         gTmMin = 0;
         gTmHr++;
         if(gTmHr >= 24){
             gTmHr = 0;
             gTmDay++;
             switch(gTmMon){
             case 2:
                 if(((gTmYr%4)==0)&&((gTmYr%100)!=0)&&((gTmYr%400)==0)){
                     if(gTmDay >= 29){
                         gTmDay = 1;
                         gTmMon++;
                     }
                 }else{
                     if(gTmDay >= 28){
                         gTmDay = 1;
                         gTmMon++;
                     }
                 }
                 break;
             case 4:
             case 6:
             case 9:
             case 11:
                 if(gTmDay >= 30){
                     gTmDay = 1;
                     gTmMon++;
                 }
                 break;
             default:    // 31 days/month
                 if(gTmDay >= 31){
                     gTmDay = 1;
                     gTmMon++;
                     if(gTmMon >= 12){
                         gTmMon = 1;
                         gTmYr++;
                     }
                 }
                 break;
             }
         }
     }
 }
}

/* Initilize parameters before run the main loop */
void InitParams(void)
{
 lcd_init();
 InitCurrentTime(2008, 9, 1, 10, 24, 12);
}

/* Power value of 10 */
int PowerTen(int p)
{
 int ret = 1;
 while(--p > 0){
     ret *= 10;
 }
 return ret;
}

/* Convert value to string */
void NumToStr(char* pMsg, int v, int len)
{
 int i;
 int p;
 for(i=0; i
     p = PowerTen(len-i);
     pMsg[i] = 0x30 + (int)(v/p);
     v %= p;
 }
}

/* Convert time value to string message */
void GetTimeMsg(char *pMsg)
{
 NumToStr(&pMsg[0], gTmMon, 2);
 pMsg[2] = '/';
 NumToStr(&pMsg[3], gTmDay, 2);
 pMsg[5] = ' ';
 NumToStr(&pMsg[6], gTmHr, 2);
 pMsg[8] = ':';
 NumToStr(&pMsg[9], gTmMin, 2);
 pMsg[11] = ':';
 NumToStr(&pMsg[12], gTmSec, 2);
 pMsg[14] = 0x00;
}

/* Display message on LCD panel */
void DisplayMessage(void)
{
 char tmMsg[16];

 lcd_goto(0);    // goto 1st line
 lcd_puts("  WIZIGN LTD.  ");

 // Convert value to string
 GetTimeMsg(tmMsg);
 lcd_goto(0x40);    // goto 2nd line
 lcd_puts(tmMsg);
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program

void main(void)
{
 // Initilize parameters
 InitParams();

 /* do loop */
 while(1){
     CalculateTime();
     DisplayMessage();
     // The LCD display and the calculation of time
     // will consume times, so, the delay time is less than 1000 ms.
     DelayMs(900);
 }
}

Wednesday, August 27, 2008

Make MCU Board - Test firmware - flash light

Consider to use the same source code between 8051 and PIC, therefore, I define constants:

#define MCU_8051 // for 8051
#define MCU_PIC // for PIC

Method 1) To control 8 LEDs, scrolling on/off, define function, void FlashLightOne(void),
**AT89S52 : use P1
**PIC16F877A : use PORTB

Method 2) To control 8 LEDs, 2 LEDs on at the same time, while the first LED is off, the next LED will be on, define funciton, void FlashLightTwo(void),
**AT89S51 : use P1
**PIC16F877A : use PORTB

main program:

/*******************************************************************************

 Copyright (c) 2008 Wizign Ltd.
    All Rights Reserved.

 main.c: Main program for demo flash light

 Date: Aug 27, 2008

 Author: YenHung Chen

 E-mail: yhchen@wizign.com

 Revision:
 ---------- -----------------------------------------------------------------
 2008/08/27 Created by YenHung Chen, demo flash light for both 8051 and PIC

 ******************************************************************************/
/*******************************************************************************



<>For AT89S52
There are 8 LEDs, which are connected P1.
Each pins of P1 is connected to one LED ligth.


<>For PIC16F877A
There are 8 LEDs, which are connected PORTB
Each pins of PORTB is connected to one LED ligth.

 ******************************************************************************/

#define MCU_8051
//#define MCU_PIC

#ifdef MCU_PIC
#include 
#else   // default is MCU_8051
#include 
#endif

#include "delay.h"

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define IO and global variables

#ifdef MCU_PIC
// Configurations
typedef unsigned int config;
config at 0x2007 __CONFIG = _RC_OSC & _PWRTE_ON & _BODEN_OFF & _WDT_OFF & _LVP_OFF;
#define gLEDs PORTB
#else   // default is MCU_8051
#define gLEDs P1
#endif

int gCount = 0;

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// define functions

/* Initilize parameters before run the main loop */
void InitParams(void)
{
    gLEDs = 0xFF;

#ifdef MCU_PIC
    TRISB = 0x00;  // output
#endif
}

/* Make a LED ON each time */
void FlashLightOne(void)
{
    unsigned char status;

    status = 1 << gCount++;
    if(gCount >= 8)
        gCount = 0;

    gLEDs = ~status;
}

/* Make two LED ON each time,
   while the preview LED is OFF, the next new LED is ON */
void FlashLightTwo(void)
{
    unsigned char status;

    status = 1 << gCount++;
    if(gCount >= 8)
        gCount = 0;

    if(status == 0x80){
        status |= 1;
    }else{
        status |= (status << 1);
    }
    gLEDs = ~status;
}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// main program

void main(void)
{
    // Initilize parameters
    InitParams();

    /* do loop */
    while(1){
        FlashLightOne();
        DelayMs(1000);
    }
}

Make MCU Board - Development Tools

I plan to program firmware on Linux platform, so I use software packages as following:

  • Fedora Core 9/Ubuntu 8.04 on PC
  • sdcc - free compiler for 8051/AVR/Z80
  • gputils - GCC compiler for PIC
  • codeblocks - IDE development tool

Installation:

* In Fedora Core 9

# yum install gputils
# yum install sdcc
# yum install codeblocks codeblocks-contrib


* In Ubuntu 8.04

# vim /etc/apt/sources.list
deb http://apt.wxwidgets.org/ gutsy-wx main
deb http://lgp203.free.fr/ubuntu/ gutsy universe

# wget -q http://apt.wxwidgets.org/key.asc -O- | apt-key add -
# wget -q http://lgp203.free.fr/public.key -O- | apt-key add -

# apt-get update
# apt-get install gputils
# apt-get install sdcc
# apt-get install codeblocks
# apt-get install codeblocks-contrib
# apt-get install libwxsmithlib0

If you want to get more optimized compiling code,
e.g. the compiled binary code is small than sdcc, and reference resource is reach,
you can consider to use HI-TECH's PICC(for PIC) or 8051 C compiler.
HI-TECH supports tool(HI-TIDE) to plugin into eclipse's IDE.