//====================================================================
//
// Author : ADI - Apps
//
// Date : 17 October 2003
//
// File : Tim2_AR.c
//
// Hardware : ADuC845
//
// Description : Flashes LED on P3.4 every approx 20Hz
//____________________________________________________________________
#include <stdio.h>
#include <ADuC845.h>
#define USE_KEY 1
unsigned char ch451_key; // 存放键盘中断中读取的键值
unsigned char th0_L;
unsigned char th0_H;
//bit cw_ccw ;
//bit enable;
#include "ch451.h"
//须主程序定义的参数
sbit L297_reset = P0^0;
sbit half_or_full = P0^1;
sbit L297_clock = P0^2;
sbit direction = P0^3;
sbit L297_enable = P0^4;
void interrupt_0 () interrupt 1
{
TL0 = 0xf0;
TH0 = th0_H;
TF0 = 0;
L297_clock=L297_clock^1;
}
void main (void)
{
unsigned char a;
ET0 = 1;
TMOD = 0x01;
TL0 = 0xf0;
th0_H=0xfa;
TH0 = th0_H;
ch451_init(); //调用初始化
ch451_write(0x403);
ch451_write(0x580); //测试送入命令
ch451_write(CH451_DIG1|0x03);
L297_reset=1;
half_or_full=0;
direction=0;
L297_enable=1;
ch451_key=0xff;
ET0=1;
EX1=1;
EA = 1;
TR0 = 1;
while(1)
{
while(ch451_key==0xff) ;
a=ch451_key;
ch451_key=0xff;
switch(a)
{
case 0x5c: direction=direction^1;ch451_write(CH451_DIG1|0x04);break;
case 0x54: th0_H=th0_H+0x01;ch451_write(CH451_DIG1|0x05);break;
case 0x4c: th0_H=th0_H-0x01;ch451_write(CH451_DIG1|0x06);break;
case 0x44: L297_enable=L297_enable^1;ch451_write(CH451_DIG1|0x07);break;
default: ch451_write(CH451_DIG1|0x02);break ;
}
}
}