最新三星单片机应用

IAR-C编程示例-S3F9454

Published:2010.11.13 NewsFrom:ZHANHENG TECHNOLOGY(HK)CO.,LTD/SHENZHEN ZHANHENGLONG ELECTRONIC CO,LTD Views:

//********************************
//产品名称: IAR-C编程示例
//使用MCU: S3F9454
//FOSC = 3.2MHZ
//以下示例中很多变量及定义可能并未
//用到,在此仅仅作为示范性列示
//********************************
#include "ioS3C9454.h"//
#include "intrinsics.h"//包含内部函数
//************************************************
//**此处为宏定义替换******
#define uchar unsigned char
#define uint  unsigned int

#define nop (__no_operation())          //将后者指令行缩写为nop;
#define di  (__disable_interrupt())     //将后者指令行缩写为di;
#define ei  (__enable_interrupt())      //将后者指令行缩写为ei;
//************************************************
//**此处定义程序所用到的全局变量*******
uchar RUNFLAG   = 0;
uchar DISPFLAG  = 0;
uchar ERRFLAG   = 0;                //错误代码标志寄存器
uchar KEY_CODE  = 0;                //键扫描码
//*************************************************************************
//***程序所用函数声明*****
//***凡程序中所用到的函数请先在这里声明***
__interrupt  void  int_9454();
void    chip_init();
void    LedScan();
//*************************************************************************
//*************************************************************************
//**定义9454的SMART OPTION值****
//**003CH,must be initialized to 0
//**003DH,must be initialized to 0
//**003EH,enable LVR(2.3V)
//**003FH,internal RC(3.2MHZ in Vdd=5V)
//*************************************
__code  const  volatile  uchar SmartOption[4] @0x003c = {0x0,0x0,0xe7,0x03};
//*************************************************************************
//*************************************************************************
//数码管显示代码定义(在ROM=0X40)
__code  const volatile uchar DigitCode[12] @0x0040 =
{
  0x03,   //'0'
  0x9f,   //'1'
  0x25,   //'2'
  0x0d,   //'3'
  0x99,   //'4'
  0x49,   //'5'
  0x41,   //'6'
  0x1f,   //'7'
  0x01,   //'8'
  0x09,   //'9'
  0xff,   //'A'
  0x61,   //'E'
};
//**************************************************************************
//========================主程序控制===========================
void main(void)
{
  uint  loop;
  //***填充系统SMART OPTION***/
  uchar buffer = SmartOption[0];
 
  //***芯片启动初始化过程***//
  chip_init();         
  //***主循环开始***//
  while(1)
  {
    P2      = 0x00;
    //以下定时取反P2口输出状态//
    for(loop=0;loop<50;loop++);
    P2      = 0xff;
    for(loop=0;loop<50;loop++);
  }
}
//******************************************************************
//****启动时IO初始化子过程******
void  chip_init()
{
    BTCON = 0xa3;         //Watch-dog disable
    CLKCON  = 0x18;       //selet non-divided CPU clock
    P0PND   = 0x0;        //P0/INT disable
    P0CONH  = 0xdf;       //P0.7 is as A/D convert port
                          //P0.6 is PWM output
                          //P0.5 is as A/D convert port 
                          //P0.4 is as A/D convert port
    P0CONL  = 0xfa;       //P0.3 is as A/D convert port
                          //P0.2 is as A/D convert port 
                          //P0.0,P0.1 is as push-pull output port
    P0 = 0x0;                                
    P1CON = 0xa;          //P1.0 is as push-pull output port 
                          //P1.1 is as push-pull output port
    P1 = 0x0;
  
    P2CONH = 0x2a;        //P2.0-P2.5 is as push-pull output
    P2CONL = 0xaa;        //P2.6 is as A/D input
    P2 = 0x1e;   
   
    PWMDATA = 0x0;
    PWMCON = 0x5c;        //PWM input clock is fosc/8,enable PWM output
                          //reload from 6 bit coun
    T0DATA = 0x32;
    T0CON =0x4a;          //TMR0 start count,f=fosc/256
                          //enable TMR0 interrupt/4ms 
    P2 = 0xff;
 
}
//*************************************************************************
//**中断向量及服务程序定义********
#pragma vector=0x00
__interrupt void int_9454()
{
  T0CON = T0CON & 0xfe;     //必须清T0中断标志
  
  LedScan();                //数码管显示扫描过程
}
//*************************************************************************
void  LedScan(void)
{
  //这里是LED显示定时扫描过程

Development tools for MCU
Programming console for MCU
Development tools for ARM
the C compiler
Contact
Samsung SCM:

ic168@zh-ic.COM

Development Tools:

B6078S@163.com

Site suggestions:

zh-ic@163.com

  Service
 MSN