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.

Thursday, August 21, 2008

單晶片開發板製作 - 主控制單元模組

希望做一塊開發板可以同時測試 8051 和 PIC, 程式可以透過 RS-232 直接燒錄,
外接電源在 9V~12V 之間, 轉換成穩壓電源 5V 和 3.3V.

目前選定的 MCU 是 ATMEL 的 AT89S51, AT89S52, 或 AT89S53 和 Microchips 的 PIC16F877A.

開發板雛型















電路圖














單晶片開發板製作

看了很多單晶片(8051 和 PIC16F)的資料, 想要驗證所學的知識, 所以計劃自行製作單晶片開發板.
開發的主軸是以建構模組的方式進行, 計劃發展的模組, 如下所列:

  • 主控制單元模組
  • 數字鐘 (LCD 顯示) 模組
  • 溫度計模組
  • USB 信號傳輸模組
  • 红外線遙控器模組 - 發射器與接收器
  • 無線傳輸遙控器模組 - 發射器與接收器
  • 馬達控制模組
  • 電波鐘模組
  • 音樂盒模組
  • 電子琴模組
  • RS 232 信號傳輸模組 - 人機介面
  • CAN 信號傳輸模組 - 行車紀錄系統
  • 定時開關模組
  • 觸控開關模組
  • 光控開關模組
  • 自走車
  • 遙控車 (遙控控制, 直流, 交流與步進馬達控制)
  • 交通號誌燈
  • LiH 充電器
  • 住家安全警報系統 - 整合應用