📄 7279.c
字号:
#include <msp430x14x.h>
//********* 7279指令 ********
#define CMD_RESET 0xA4 //复位(清除)
#define CMD_TEST 0xBF //测试
#define CMD_READ 0x15 //读键盘数据指令
#define RL_CYCLE 0xA3 //循环左移
#define RR_CYCLE 0xA2 //循环右移
#define RL_UNCYL 0xA1 //左移
#define RR_UNCYL 0xA0 //右移
#define DECODE0 0x80 //下载数据,按方式0译码 DECODE0+地址, 数据
#define DECODE1 0xC8 //下载数据,按方式1译码 DECODE1+地址, 数据
#define UNDECODE 0x90 //下载数据,不译码 UNDECODE+地址,数据(码字)〓1-亮;0-灭
#define ACTCTL 0x98 //消隐控制 ACTCTL,数据(d8-d0;1-亮;0-灭)
#define BLINK 0x88 //闪烁显示 BLINK, 数据(d8-d0;0-闪烁;1-不闪烁)
#define SEGON 0xE0 //段点亮
#define SEGOFF 0xC0 //段关闭
idata uchar key_number=0xff;
//7279端口定义
#define CS P3DIR |= BIT0 //片选输出
#define CLK P3DIR |= BIT1 //时钟输出
#define DAT P3DIR |= BIT2
#define KEY P3DIR &=~ BIT3 //I/O口为输入 //接P3。2为外部中断0输入
//7279驱动
void Send_Byte( uchar ); //发送一个字节
void Write7279( uchar, uchar ); //写入到7279
uchar Read7279( void ); //读7279
uchar Receive_Byte( void ); //接收一个字节
void L_Delay(); //延时 */
void S_Delay();
void Delay10ms( uint n ) ;
//*********** 长延时 *************
void L_Delay() //CS被清零后,要经过50μs,才送CLK.
{
idata uchar i;
for ( i=0; i<48; i++ ) ;
}
//*********** 短延时 *************
void S_Delay() //在传送指令或字节时,CLK要持续8μs的高电平.
{
idata uchar i;
for ( i=0; i<8; i++ ) ;
}
//*********** 延时 n*10ms *******
void Delay10ms( uint n )
{
idata uint j;
while( n-- )
{
for ( j=0; j<912; j++ );
}
}
//*********** 写入到7279 ******* //让LED显示
void Write7279( uchar CMD, uchar DTA )
{
Send_Byte( CMD );
Send_Byte( DTA );
}
//*********** 读7279 ************* //读键盘按键
uchar Read7279( void )
{
Send_Byte( CMD_READ );
return( Receive_Byte());
}
//*********** 发送一个字节 *************
void Send_Byte( uchar out_byte )
{
idata uchar i;
CS=0;
L_Delay();
for( i=0; i<8; i++ )
{
if (out_byte&0x80 ) { DAT=1; }
else { DAT=0; }
CLK = 1;
S_Delay();
CLK = 0;
S_Delay();
out_byte = out_byte<<1;
}
DAT=0;
}
//*********** 读一个字节 ***************
uchar Receive_Byte()
{
idata uchar i, IN_Byte=0x00;
DAT =1;
L_Delay();
for( i=0; i<8; i++ )
{
CLK = 1;
S_Delay();
IN_Byte = IN_Byte<<1;
if (DAT ) { IN_Byte = IN_Byte|0x01; }
CLK = 0;
S_Delay();
}
DAT=0;
return ( IN_Byte ) ;
}
void main()
{
key_number=OX02;
void Write7279( uchar CMD, uchar DTA );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -