原创 ZLG7289 MSP430程序

2007-7-7 12:18 4780 12 5 分类: MCU/ 嵌入式

自己写的原创的阿


我的网站http://www.just430.cn 淘宝http://shop34362821.taobao.com/


同时出售ZLG7289模块


/**********************************************************/
//MSP430 Advanced Developping Components - [ZLG7289_430.C]
////ZLG7289 KeyBroad and LEDs Developping Demos
////->>> http://www.just430.cn
////->>> tel 0)13500717874
/**********************************************************/
//MSP430高级实验开发组件 - ZLG7289键盘显示组件示例程序
//时钟设置:
////ACLK=N/A,MCLK=SMCLK=default(DCO~800k)
//硬件连接:
////     MSP430 Broad               ZLG7289 Broad
////   ------------------         ------------------
////   |      VCC       | ------> |      VCC       |
////   |      P65       | ------> |      CS        |
////   |      P64       | ------> |      CLK       |
////   |      P63       | <-----> |      DAT       |
////   |      P24       | <------ |    KEY(INT)    |
////   |      GND       | ------> |      GND       |
////   ------------------         ------------------
//当前演示程序功能描述:
////当有按键按下时,430进入中断读取键值,显示在LED数码管上
/*********************************************************/


#include


#define Z7289_CS  BIT5
#define Z7289_CLK  BIT4
#define Z7289_DAT  BIT3
#define Z7289_KEY  BIT4


#define Z7289_DIR  P6DIR
#define Z7289_OUT  P6OUT
#define Z7289_IN  P6IN
#define Z7279_INT_DIR  P2DIR
#define Z7279_INT_IE  P2IE
#define Z7279_INT_IES  P2IES
#define Z7279_INT_IFG  P2IFG   //定义MSP430端口


#define Z7289_CS_LO  Z7289_OUT &= ~Z7289_CS
#define Z7289_CS_HI  Z7289_OUT |= Z7289_CS
#define Z7289_CLK_LO         Z7289_OUT &= ~Z7289_CLK
#define Z7289_CLK_HI  Z7289_OUT |= Z7289_CLK
#define Z7289_DAT_LO         Z7289_OUT &= ~Z7289_DAT
#define Z7289_DAT_HI  Z7289_OUT |= Z7289_DAT


#define Z7289_RESET  Z7289_Send1(0xA4)
#define Z7289_TEST  Z7289_Send1(0xBF)
#define Z7289_LMOV  Z7289_Send1(0xA1)
#define Z7289_RMOV  Z7289_Send1(0xA0)
#define Z7289_RLMOV  Z7289_Send1(0xA3)
#define Z7289_RRMOV  Z7289_Send1(0xA2) //定义ZLG7289功能


const unsigned char DelayConst = 0;   //系统延时
const unsigned char Code[3]={    //显示方式
 0x80,0xC8,0x90
};
const unsigned char Keys[16]={    //按键编码
 0x02,0x30,0x32,0x34,0x20,0x22,0x24,0x10,0x12,0x14,0x36,0x26,0x16,0x06,0x00,0x04
};


void Z7289_Delayt(unsigned int dtime);
void Z7289_Send1(unsigned char dat);
void Z7289_Send2(unsigned char add,unsigned char dat);
void Z7289_Show(unsigned char add,unsigned char coding,unsigned char d);
void Z7289_Init(void);
void OSC_Init(void);
unsigned char Z7289_ReadKey(void);


/****************************
void main(void) {
 WDTCTL = WDTPW + WDTHOLD;
 Z7289_Init();
 Z7279_INT_DIR &= ~Z7289_KEY;
 Z7279_INT_IE  |= Z7289_KEY;
 Z7279_INT_IES |= Z7289_KEY;
 _BIS_SR(GIE);
 while(1);
}
****************************/


//中断服务程序
////读取键值并显示
#pragma vector="PORT2"_VECTOR
__interrupt void PORT2_ISR (void) {
 unsigned char keyword;
 unsigned int i;
 keyword = Z7289_ReadKey();
 for(i=0;i<8;i++) {
  Z7289_Show(i,1,keyword);
 }
 Z7279_INT_IFG = 0;
}


//初始化程序
////设定端口和中断,初始化ZLG7289
void Z7289_Init(void) {
 Z7289_DIR |= (Z7289_CS + Z7289_CLK + Z7289_DAT);
 Z7289_CS_HI;
 Z7289_CLK_LO;
 Z7289_RESET;
}


//向ZLG7289发送一个字节(命令)
void Z7289_Send1(unsigned char dat) {
 unsigned char itemp;
 Z7289_CS_LO;
 Z7289_Delayt(1);
 for(itemp=0;itemp<8;itemp++) {
  if((dat<   Z7289_DAT_HI;
  else
   Z7289_DAT_LO;
  Z7289_Delayt(1);
  Z7289_CLK_HI;
  Z7289_Delayt(1);
  Z7289_CLK_LO;
 }
 Z7289_CS_HI;
}


//向ZLG7289发送两个字节(命令+数据)
void Z7289_Send2(unsigned char add,unsigned char dat) {
 unsigned char itemp;
 Z7289_CS_LO;
 Z7289_Delayt(1);
 for(itemp=0;itemp<8;itemp++) {
  if((add<   Z7289_DAT_HI;
  else
   Z7289_DAT_LO;
  Z7289_Delayt(1);
  Z7289_CLK_HI;
  Z7289_Delayt(1);
  Z7289_CLK_LO;
 }
 Z7289_Delayt(1);
 for(itemp=0;itemp<8;itemp++) {
  if((dat<   Z7289_DAT_HI;
  else
   Z7289_DAT_LO;
  Z7289_Delayt(1);
  Z7289_CLK_HI;
  Z7289_Delayt(1);
  Z7289_CLK_LO;
 } 
 Z7289_CS_HI;
}


//按照编码方式显示字符
void Z7289_Show(unsigned char add,unsigned char coding,unsigned char d) {
 Z7289_Send2(Code[coding]+add,d);
}


//向ZLG7289发送命令后,读取按键键值,并查表返回结果
unsigned char Z7289_ReadKey(void) {
 unsigned char itemp;
 unsigned char dat;
 dat = 0x15;
 Z7289_CS_LO;
 Z7289_Delayt(1);
 for(itemp=0;itemp<8;itemp++) {
  if((dat<   Z7289_DAT_HI;
  else
   Z7289_DAT_LO;
  Z7289_Delayt(1);
  Z7289_CLK_HI;
  Z7289_Delayt(1);
  Z7289_CLK_LO;
 }
 Z7289_DIR &= ~Z7289_DAT;
 Z7289_Delayt(1);
 for(itemp=0;itemp<8;itemp++) {
  Z7289_CLK_HI;
  Z7289_Delayt(1);
  Z7289_CLK_LO;
  dat<<=1;
  if((Z7289_IN&Z7289_DAT) == Z7289_DAT)
   dat |= BIT0;
  else
   dat &= ~BIT0;
 }
 Z7289_DIR |= Z7289_DAT;
 Z7289_CS_HI;
 for(itemp=0;itemp<16;itemp++)
  if(dat==Keys[itemp])
   break;
 return itemp;
}


void Z7289_Delayt(unsigned int dtime) {
 unsigned int itemp,jtemp;
 for(itemp=0;itemp  for(jtemp=0;jtemp}


 


 

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
12
关闭 站长推荐上一条 /3 下一条