打印

用义隆C语言写的一个简单小家电控制器

[复制链接]
7642|16
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
brmcu|  楼主 | 2008-5-7 01:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "EM78x156xx.h"

#define DISI()    _asm{disi}
#define ENI()    _asm{eni}
#define SLEP()    _asm{slep}
#define NOP()    _asm{nop}
#define WDTC()  _asm{wdtc}

#define uchar unsigned int
#define uint  unsigned short


#define Key  R53
#define Bz   R51
#define Out  R50
#define Com1 R60
#define Com2 R61
#define Com3 R62
#define Seg1 R63
#define Seg2 R64
#define Seg3 R65
#define Seg4 R66
#define Seg5 R67
#define InCom1 (P6CR|=0x01)
#define InCom2 (P6CR|=0x02)
#define InCom3 (P6CR|=0x04)
#define OutCom1 (P6CR&=0x0E)
#define OutCom2 (P6CR&=0x0D)
#define OutCom3 (P6CR&=0x0B)

bit OkFlag;
bit BzOutFlag;
bit StartFlag;
bit KeyFlag;
uchar Count @0x2F;
uint BzOutTime;
uint TimeFlag;
uchar Minute;
uchar Second;
uchar BiasTime;

const uchar Number1[10]={
0x6F,0x06,0x3D,0x37,0x56,0x73,0x7B,0x26,0xFF,0x77};
const uchar Number2[10]={
0xF7,0x03,0x5E,0x1F,0x8B,0x9D,0xFD,0x13,0xFF,0xBF};



void SysInt(void);
void KeyProcess(void);
void Delayms(uint ms);
void BzOut(void);
void LcdDisplay(uchar Num1,uchar Num2);
void TimeDisplay(void);

void main()
{
 SysInt();
 while(1)
 {
  KeyProcess();
  TimeDisplay();
 }
}

void TimeDisplay(void)
{
 uchar temp1,temp2;
 //Count++;
 Out=!StartFlag;
 if(BzOutFlag==1)
 {
  if((BzOutTime%1000)==0)
  BzOut();
  if(BzOutTime>=20000)
  {
   BzOutTime=0;
   BzOutFlag=0;
  }
  BzOutTime++;
 }
 if((Count>=249)&&(StartFlag==1))//Count>=249
 {
  Count=0;
  if(Second>0)
  Second--;
  if(Second==0)
  {
   if(Minute>0)
   {
    Minute--;
    Second=60;
   }
   else
   {
    StartFlag=0;
    BzOutFlag=1;
    OkFlag=1;
   }
  }
 }
 if(OkFlag==1)
 {
  LcdDisplay(0x0,0x0);
 }
 else if(Minute>=1)
  {
   if((Minute>=1)&&(Second>0)&&(StartFlag==1))
   {
    temp2=(Minute+1)/10;
    temp1=(Minute+1)%10;
   }
   else
   {
    temp2=Minute/10;
    temp1=Minute%10;
   }
   
   if((StartFlag==1)&&(Count>125))
   {
    LcdDisplay(0x00,0x00);
   }
   else
   {LcdDisplay(Number1[temp1],Number2[temp2]);}
  }
  else
  {
   temp2=Second/10;
   temp1=Second%10;
   LcdDisplay(Number1[temp1],Number2[temp2]);
  }
  
 
}

void SysInt(void)
{
 WDTCR=0;
 DISI();
 _asm
 {
  mov a,@0x44
  contw
 }    
 ISR=0;
 IMR=0x01;
 TCC=5;
 PHCR=0xFF;
 PDCR=0xFF;
 P5CR=0x08;
 P6CR&=0x07;
 InCom1;
 InCom2;
 InCom3;
 Seg1=0;
 Seg2=0;
 Seg3=0;
 Seg4=0;
 Seg5=0;
 BiasTime=0;
 BzOutTime=0;
 TimeFlag=0;
 OkFlag=0;
 StartFlag=0;
 BzOutFlag=0;
 Count=0;
 Second=0;
 Minute=0;
 Bz=0;
 Out=1;
 KeyFlag=0;
 ENI();
}

void LcdDisplay(uchar Num1,uchar Num2)
{
 switch(BiasTime)
 {
  case 0:
        OutCom1;
        Com1=1;
        InCom2;
        InCom3;
        if((Num1&0x01)==0)Seg1=1;
        else Seg1=0;
        if((Num1&0x08)==0)Seg2=1;
        else Seg2=0;
        if((Num2&0x01)==0)Seg3=1;
        else Seg3=0;
        if((Num2&0x04)==0)Seg4=1;
        else Seg4=0;
        if((Num2&0x20)==0)Seg5=1;
        else Seg5=0;
        break;
   case 1:  
        OutCom1;
        Com1=0;
        InCom2;
        InCom3;
        if((Num1&0x01)==0)Seg1=0;
        else Seg1=1;
        if((Num1&0x08)==0)Seg2=0;
        else Seg2=1;
        if((Num2&0x01)==0)Seg3=0;
        else Seg3=1;
        if((Num2&0x04)==0)Seg4=0;
        else Seg4=1;
        if((Num2&0x20)==0)Seg5=0;
        else Seg5=1;
        break;
   case 2:
        InCom1;
        OutCom2;
        Com2=1;
        InCom3;
        if((Num1&0x02)==0)Seg1=1;
        else Seg1=0;
        if((Num1&0x10)==0)Seg2=1;
        else Seg2=0;
        if((Num2&0x02)==0)Seg3=1;
        else Seg3=0;
        if((Num2&0x08)==0)Seg4=1;
        else Seg4=0;
        if((Num2&0x40)==0)Seg5=1;
        else Seg5=0;
        break;
   case 3:
        InCom1;
        OutCom2;
        Com2=0;
        InCom3;
        if((Num1&0x02)==0)Seg1=0;
        else Seg1=1;
        if((Num1&0x10)==0)Seg2=0;
        else Seg2=1;
        if((Num2&0x02)==0)Seg3=0;
        else Seg3=1;
        if((Num2&0x08)==0)Seg4=0;
        else Seg4=1;
        if((Num2&0x40)==0)Seg5=0;
        else Seg5=1;
        break;
  case 4: 
        InCom1;
        InCom2;
        OutCom3;
        Com3=1;
        if((Num1&0x04)==0)Seg1=1;
        else Seg1=0;
        if((Num1&0x20)==0)Seg2=1;
        else Seg2=0;
        if((Num1&0x40)==0)Seg3=1;
        else Seg3=0;
        if((Num2&0x10)==0)Seg4=1;
        else Seg4=0;
        if((Num2&0x80)==0)Seg5=1;
        else Seg5=0;
        break;
  case 5:
        InCom1;
        InCom2;
        OutCom3;
        Com3=0;
        if((Num1&0x04)==0)Seg1=0;
        else Seg1=1;
        if((Num1&0x20)==0)Seg2=0;
        else Seg2=1;
        if((Num1&0x40)==0)Seg3=0;
        else Seg3=1;
        if((Num2&0x10)==0)Seg4=0;
        else Seg4=1;
        if((Num2&0x80)==0)Seg5=0;
        else Seg5=1;
 default:break;
 }    
 Delayms(1);
 BiasTime++;
 if(BiasTime>=6)
 BiasTime=0;
}

void KeyProcess(void)

 if((TimeFlag>0)&&(TimeFlag<2000))
 {
  OkFlag=0;
  TimeFlag++;
  if(TimeFlag>=2000)
  StartFlag=1;
 }
 
 if((Key==0)&&(KeyFlag==0)&&(StartFlag==0))
 {
  TimeFlag=1;
  Minute++;
  if(Minute>99)
  Minute=0;
  if(OkFlag==1)
  {
   //OkFlag=0;
  // Minute=0;
   SysInt();
  }
  KeyFlag=1;
 }
 else
 {
  if(Key==1)
  KeyFlag=0;
  
  if((Key==0)&&(KeyFlag==0)&&(StartFlag==1))
  {
   SysInt();
   KeyFlag=1;
  }
 }
}

void BzOut(void)
{
 uchar i,j;
 for(i=0;i<150;i++)
 {
  Bz=!Bz;
  for(j=0;j<58;j++)
  {NOP();NOP();}
 }
  /*Delayms(50);
  for(i=0;i<100;i++)
 {
  Bz=!Bz;
  for(j=0;j<50;j++)
  {NOP();NOP();}
 }*/
  Bz=0;
}

void Delayms(uint ms)
{
 uint i,j;
 for(i=0;i<ms;i++)
 for(j=0;j<120;j++)
 NOP();
}


void _intcall interrupt_l(void) @0x08:low_int 0
{
  _asm 
   {
      //save A --> 0x1F ; R3 --> 0x3E (ram bank 1); R4 --> 0x3F (ram bank 1)
      MOV 0X1F,A   ;backup A to 0x1F
      SWAPA 0X04   ;backup R4 to 0x3F at bank 3
      MOV 0X3F,A   ;backup R4 to 0x3F at bank 3
      SWAPA 0X03   
      MOV 0X3E,A   ;backup R3 to 0x3E at bank 3
   }     
}
void _intcall interrupt(void) @int 0
{
 if(TCIF==0)return;
 DISI();
 ISR=0;
  _asm
 {
  mov a,@0x44
  contw
 }    
 TCC=5;
 _asm
 {
  SWAPA 0X3E   ;restore R3
  MOV 0X03,A
  SWAPA 0X3F   ;restore R4
  MOV 0X04,A
  SWAP 0X1F    ;restore A
  SWAPA 0X1F
  }
  _asm{INC 0X2F}
 ENI();
}

相关帖子

沙发
hkap| | 2008-5-7 09:21 | 只看该作者

义隆C编译器好用么,以前用15X都用汇编写

使用特权

评论回复
板凳
brmcu|  楼主 | 2008-5-7 11:18 | 只看该作者

都差不多,以前听说有BUG,我碰到过,只要熟悉哪些地方有BUG就

都差不多,以前听说有BUG,我碰到过,只要熟悉哪些地方有BUG就可以

使用特权

评论回复
地板
gyt| | 2008-5-7 14:17 | 只看该作者

谢谢发表

使用特权

评论回复
5
huangqi412| | 2008-5-7 19:46 | 只看该作者

lz 突然冒出来的哈

使用特权

评论回复
6
brmcu|  楼主 | 2008-5-8 12:52 | 只看该作者

怎么突然了呢?呵呵

怎么突然了呢?呵呵

使用特权

评论回复
7
brmcu|  楼主 | 2008-5-8 18:20 | 只看该作者

义隆C还是可以的只是相对KEIL来讲差些,比起台湾其他的要好

使用特权

评论回复
8
谈的元| | 2008-5-8 22:38 | 只看该作者

记号

使用特权

评论回复
9
brmcu|  楼主 | 2008-5-9 12:15 | 只看该作者

这个是用单片机IO口直接驱动LCD的

使用特权

评论回复
10
voynich| | 2008-5-9 12:31 | 只看该作者

为了忘却的纪念!

不搞EMC已经有几个年头了,那时候义隆的C语言刚出来!
LZ的程序让我想起了,我用汇编语言调试EMC的那些奋斗的日子!哈

使用特权

评论回复
11
98dian| | 2008-5-9 12:48 | 只看该作者

小弟正要用它

楼上各位能否推荐个C编译器的下载地址或名字,我要研究一下,这片子好用吗?听说成本很低,有没有C的DEMO程序啊?

使用特权

评论回复
12
brmcu|  楼主 | 2008-5-10 20:45 | 只看该作者

义隆公司网站就有下,上面也有C的例程

使用特权

评论回复
13
yysmcu| | 2008-5-12 00:10 | 只看该作者

没用过义隆

使用特权

评论回复
14
hotpower| | 2008-5-12 00:16 | 只看该作者

不太感冒~~~

使用特权

评论回复
15
方谭| | 2008-5-25 07:46 | 只看该作者

刚去义隆的网站看一看,原来它有Flash的,还可以ISP下载!

不知它的flash系列价钱怎样呢??

使用特权

评论回复
16
hungrywolf| | 2008-5-29 10:02 | 只看该作者

那个型号啊?

义隆的我都是用汇编写的,你这里那么多语句,能容得下吗??哪个型号的?

使用特权

评论回复
17
etual| | 2008-5-29 11:23 | 只看该作者

同行,顶一下~~

不过楼主最好加点注释,不写注释的习惯是不好di.....

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

22

主题

151

帖子

0

粉丝