sbit ADDR0 = P1^0
sbit ADDR1 = P1^1
sbit ADDR2 = P1^2
sbit ADDR3 = P1^3
sbit ENLED = P1^4
unsigned char code image[11][8] = {
{0xC3, 0x81, 0x99, 0x99, 0x99, 0x99, 0x81, 0xC3}, //数字0
{0xEF, 0xE7, 0xE3, 0xE7, 0xE7, 0xE7, 0xE7, 0xC3}, //数字1
{0xC3, 0x81, 0x9D, 0x87, 0xC3, 0xF9, 0xC1, 0x81}, //数字2
{0xC3, 0x81, 0x9D, 0xC7, 0xC7, 0x9D, 0x81, 0xC3}, //数字3
{0xCF, 0xC7, 0xC3, 0xC9, 0xC9, 0x81, 0xCF, 0xCF}, //数字4
{0x81, 0xC1, 0xF9, 0xC3, 0x87, 0x9D, 0x81, 0xC3}, //数字5
{0xC3, 0x81, 0xF9, 0xC1, 0x81, 0x99, 0x81, 0xC3}, //数字6
{0x81, 0x81, 0x9F, 0xCF, 0xCF, 0xE7, 0xE7, 0xE7}, //数字7
{0xC3, 0x81, 0x99, 0xC3, 0xC3, 0x99, 0x81, 0xC3}, //数字8
{0xC3, 0x81, 0x99, 0x81, 0x83, 0x9F, 0x83, 0xC1}, //数字9
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //全亮
}
void main()
{
EA = 1 //使能总中断
ENLED = 0 //使能U4,选择LED点阵
ADDR3 = 0
TMOD = 0x01 //设置T0为模式1
TH0 = 0xFC //为T0赋初值0xFC67,定时1ms
TL0 = 0x67
ET0 = 1//使能T0中断
TR0 = 1//启动T0
while (1)
}
void InterruptTimer0() interrupt 1
{
static unsigned char i = 0 //动态扫描的索引
static unsigned int tmr = 0 //1s软件定时器
static unsigned char index = 9 //图片刷新索引
TH0 = 0xFC //重新加载初值
TL0 = 0x67
//以下代码完成LED点阵动态扫描刷新
P0 = 0xFF //显示消隐
switch (i)
{
case 0: ADDR2=0ADDR1=0ADDR0=0i++P0=image[index][0]break
case 1: ADDR2=0ADDR1=0ADDR0=1i++P0=image[index][1]break
case 2: ADDR2=0ADDR1=1ADDR0=0i++P0=image[index][2]break
case 3: ADDR2=0ADDR1=1ADDR0=1i++P0=image[index][3]break
case 4: ADDR2=1ADDR1=0ADDR0=0i++P0=image[index][4]break
case 5: ADDR2=1ADDR1=0ADDR0=1i++P0=image[index][5]break
case 6: ADDR2=1ADDR1=1ADDR0=0i++P0=image[index][6]break
case 7: ADDR2=1ADDR1=1ADDR0=1i=0P0=image[index][7]break
default: break
}
//以下代码完成每秒改变一帧图像
tmr++
if (tmr >= 1000) //达到1000ms时改变一次图片索引
{
tmr = 0
if (index == 0) //图片索引10~0循环
index = 10
else
index--
}
}
include <c8051f330.h>#include <stdio.h>
#include <math.h>
#include <Intrins.h>
#include <absacc.h>
#define SPEED 2000
#define TIME 1800
#define uint unsigned int
#define uchar unsigned char
#define BLKN 2 //用于点阵列扫描的595的个数
#define TOTAL 26 //待显示的字数
#define CONIO P1
uchar number//d=0,
uchar control=0,choose,send
uchar receive_number=3,send_number=0
bit BUSY
bit SMB_RW
uchar hou=0
uchar min=0
uchar sec=0
uchar sg//时高位
uchar sd//时低位
uchar fg//分高位
uchar fd//分低位
uchar mg//秒高位
uchar md//秒低位
sbit CLK=P1^7 //输出脉冲
sbit scyx=P1^6 //复位
sbit led=P0^7
sbit pcf8563_scl=P0^5//时钟频率
sbit pcf8563_sda=P0^4//串行数据传输脚
uchar idata dispram[(BLKN/2)*32]={0}
uchar receive1[3]={0x00,0x00,0x00}//时、分、秒
uchar send1[4]={0x02,0x33,0x25,0x03}//时、分、秒、器件地址
/*********************************字模表***************************************/
uchar code Bmp[][32]={
{0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x1C,0x18,0x38,0x1C,0x38,0x0E,0x38,0x0E,
0x78,0x0E,0x38,0x0E,0x38,0x0E,0x38,0x1C,0x1C,0x18,0x07,0xF0,0x00,0x00,0x00,0x00},
/***数字0***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x0F,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,
0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x01,0xC0,0x0F,0xFC,0x00,0x00,0x00,0x00},
/***数字1***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x18,0x1C,0x38,0x1C,0x18,0x1C,0x00,0x38,
0x00,0x70,0x01,0xC0,0x07,0x00,0x0C,0x06,0x3F,0xFC,0x3F,0xFC,0x00,0x00,0x00,0x00},
/***数字2***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x38,0x38,0x38,0x1C,0x00,0x38,0x03,0xF0,
0x03,0xF0,0x00,0x1C,0x00,0x0E,0x38,0x1C,0x38,0x1C,0x0F,0xF0,0x00,0x00,0x00,0x00},
/***数字3***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0xF0,0x01,0xF0,0x03,0x70,0x0C,0x70,
0x18,0x70,0x30,0x70,0x3F,0xFE,0x00,0x70,0x00,0x70,0x03,0xFE,0x00,0x00,0x00,0x00},
/***数字4***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFC,0x18,0x00,0x18,0x00,0x18,0xC0,0x1F,0xF8,
0x18,0x1C,0x00,0x1E,0x10,0x0E,0x38,0x1C,0x38,0x18,0x0F,0xF0,0x00,0x00,0x00,0x00},
/***数字5***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF8,0x0C,0x3C,0x18,0x08,0x38,0x00,0x3F,0xF8,
0x7C,0x1C,0x78,0x0E,0x38,0x0E,0x38,0x0E,0x1C,0x1C,0x07,0xF0,0x00,0x00,0x00,0x00},
/***数字6***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0xFE,0x3C,0x0C,0x30,0x18,0x00,0x30,0x00,0x60,
0x00,0xC0,0x01,0xC0,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x00,0x00,0x00,0x00},
/***数字7***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x38,0x0C,0x30,0x0E,0x3C,0x0C,0x1F,0xF8,
0x0F,0xF0,0x38,0x3C,0x30,0x0E,0x70,0x0E,0x38,0x0C,0x0F,0xF0,0x00,0x00,0x00,0x00},
/***数字8***/
{0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF0,0x38,0x18,0x30,0x0C,0x70,0x0E,0x30,0x0E,
0x38,0x3E,0x1F,0xEE,0x00,0x1C,0x18,0x18,0x3C,0x30,0x1F,0xE0,0x00,0x00,0x00,0x00},
/***数字9***/
{0x00,0x40,0x40,0x40,0x30,0x40,0x10,0x40,0x00,0x48,0x00,0x7C,0xF0,0x40,0x10,0x40,
0x10,0x40,0x10,0x40,0x10,0x40,0x12,0x40,0x14,0x40,0x18,0x44,0x17,0xFE,0x00,0x00},//让
{0x00,0x08,0x3F,0xFC,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x21,0x08,
0x21,0x08,0x3F,0xF8,0x20,0x08,0x02,0x00,0x51,0x88,0x50,0x96,0x90,0x12,0x0F,0xF0},//思
{0x10,0x80,0x10,0xA0,0x20,0x94,0x21,0xFE,0x49,0x10,0xFB,0x10,0x15,0xFC,0x21,0x10,
0x41,0x10,0xFD,0xFC,0x01,0x10,0x01,0x10,0x1D,0x14,0xE1,0xFE,0x41,0x00,0x01,0x00},//维
{0x01,0x20,0x41,0x24,0x2F,0xFE,0x21,0x24,0x01,0x24,0x8F,0xFC,0x49,0x24,0x09,0x20,
0x1F,0xFE,0x29,0x22,0xE1,0x22,0x21,0x2A,0x22,0x24,0x22,0x20,0x24,0x20,0x28,0x20},//沸
{0x00,0x40,0x7A,0x48,0x49,0x50,0x4B,0xFC,0x48,0x80,0x7F,0xFE,0x49,0x10,0x4A,0x0E,
0x4D,0xF4,0x78,0x10,0x49,0x14,0x49,0xFE,0x48,0x04,0x4F,0xE4,0x88,0x14,0x18,0x08},//腾
{0x08,0x00,0x08,0x08,0x08,0xFC,0x7E,0x08,0x08,0x08,0x08,0x08,0xFE,0xF8,0x08,0x88,
0x28,0x80,0x2E,0x84,0x28,0x84,0x28,0x7C,0x28,0x00,0x58,0x06,0x8F,0xFC,0x00,0x00},//起
{0x01,0x00,0x01,0x00,0x01,0x08,0x7F,0xFC,0x01,0x00,0x21,0x10,0x19,0x30,0x09,0x44,
0xFF,0xFE,0x03,0x80,0x05,0x40,0x09,0x30,0x31,0x1E,0xC1,0x04,0x01,0x00,0x01,0x00},//来
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0C,0x00,0x1E,0x00,0x1E,0x00,0x0C,0x00,0x04,0x00,0x08,0x00,0x10,0x00,0x00,0x00},//,
{0x00,0x40,0x40,0x40,0x30,0x40,0x10,0x40,0x00,0x48,0x00,0x7C,0xF0,0x40,0x10,0x40,
0x10,0x40,0x10,0x40,0x10,0x40,0x12,0x40,0x14,0x40,0x18,0x44,0x17,0xFE,0x00,0x00},//让
{0x20,0x00,0x22,0x04,0x3F,0x7E,0x48,0x44,0x08,0x44,0xFF,0xC4,0x10,0x44,0x14,0x7C,
0x22,0x44,0x42,0x10,0x9F,0xF8,0x10,0x10,0x1F,0xF0,0x10,0x10,0x1F,0xF0,0x10,0x10},//智
{0x08,0x20,0x7E,0xFC,0x08,0x20,0x3E,0xF8,0x08,0x20,0x7E,0xFC,0x08,0x20,0x3F,0xF8,
0x00,0x08,0xFF,0xFE,0x00,0x08,0x3F,0xF8,0x09,0x00,0x28,0xA8,0x48,0x24,0x07,0xE0},//慧
{0x08,0x08,0x0B,0xFC,0x10,0x00,0x20,0x00,0x40,0x00,0x08,0x04,0x17,0xFE,0x30,0x10,
0x50,0x10,0x90,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x50,0x10,0x20},//行
{0x00,0x40,0x08,0x40,0x7C,0x40,0x00,0x44,0x05,0xFE,0xFE,0x44,0x10,0x44,0x10,0x44,
0x20,0x44,0x24,0x44,0x42,0x84,0xFE,0x84,0x41,0x04,0x01,0x04,0x02,0x28,0x04,0x10},//动
{0x08,0x00,0x08,0x08,0x08,0xFC,0x7E,0x08,0x08,0x08,0x08,0x08,0xFE,0xF8,0x08,0x88,
0x28,0x80,0x2E,0x84,0x28,0x84,0x28,0x7C,0x28,0x00,0x58,0x06,0x8F,0xFC,0x00,0x00},//起
{0x01,0x00,0x01,0x00,0x01,0x08,0x7F,0xFC,0x01,0x00,0x21,0x10,0x19,0x30,0x09,0x44,
0xFF,0xFE,0x03,0x80,0x05,0x40,0x09,0x30,0x31,0x1E,0xC1,0x04,0x01,0x00,0x01,0x00},//来
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x3C,0x00,0x66,0x00,0x66,0x00,0x66,0x00,0x3C,0x00,0x00,0x00},//.}
uchar code Bmp1[][32]={
{0x01,0x00,0x11,0x00,0x11,0x00,0x11,0x08,0x3F,0xFC,0x21,0x00,0x41,0x00,0x41,0x00,
0x81,0x10,0x3F,0xF8,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x04,0xFF,0xFE,0x00,0x00},
{0x00,0x10,0x1F,0xF8,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x1F,0xF0,0x10,0x10,0x00,0x00},
{0x10,0x80,0x10,0x80,0x10,0x80,0x10,0x88,0x5B,0xFC,0x54,0x88,0x50,0x88,0x90,0x88,
0x10,0x88,0x1F,0xFE,0x10,0x80,0x11,0x40,0x11,0x20,0x12,0x10,0x14,0x0E,0x18,0x04},
{0x00,0x20,0x00,0xF0,0x1F,0x00,0x10,0x00,0x11,0x00,0x11,0x00,0x21,0x04,0x7F,0xFE,
0x01,0x00,0x01,0x00,0x09,0x20,0x09,0x10,0x11,0x08,0x21,0x0C,0x45,0x04,0x02,0x00},
{0x00,0x00,0x38,0x1C,0x44,0x22,0x54,0x2A,0x44,0x22,0x37,0xEC,0x08,0x10,0x10,0x08,
0x2E,0x74,0x20,0x04,0x21,0x84,0x24,0x24,0x13,0xC8,0x08,0x10,0x07,0xE0,0x00,0x00}
}
/*********************************字模表***************************************/
/************系统函数的配置***********/
void sysclk_int(void)//内部晶振
{
OSCICL=0x83
OSCICN=0xc3//不分频
CLKSEL=0x00
}
/*
void delay1(uchar n) //延时程序
{
uchar j
for(j=0j<nj++)
{
_nop_()
_nop_()
_nop_()
_nop_()
}
}
*/
void delay(uint i) //毫秒延时
{
register uchar j//
for(ii--)
for(j=0j<255j++)
}
void SPI_INT(void) //SPI初始化
{
SPI0CFG=0x40
SPI0CN=0x01//0000 0001最后一位是SPI使能位 SPI工作在三线主方式
SPI0CKR=0x0f//SPI 时钟频率设置为100kHz 0x63
IE &= 0xbf //关闭SPI中断
}
void SMB_INT(void) //SMB初始化
{
SMB0CF=0x5f//使能SMB 允许时间扩充 定时器2低字节溢出时钟源
SMB0CF|=0x80
}
void TIME01_INT(void) //定时器初始化
{
TCON=0x10 //定时器0允许
TMOD=0x01 //定时器0在16位工作方式
CKCON &= 0xf8
CKCON |= 0x01 //定时器0使用系统4分频
TL0=0x03
TH0=0x03
IE|=0x02
}
void TIME2_INT(void) //定时器2用于配置SMB的时钟频率
{
TMR2CN=0x00
CKCON |= 0x00
TMR2RLL = 0xef
TMR2RLH = 0xff
TMR2L = 0xef
TMR2H = 0xff
TMR2CN |= 0x0c
}
void TIME3_INT(void)//用于I2C的超时检测
{
TMR3CN = 0x00 //定时器3为16位自动重载
CKCON &= ~0x40
TMR3RLL = 0xaf
TMR3RLH = 0x57
TMR3L = 0xaf
TMR3H = 0x57
EIE1|=0x00
TMR3CN |= 0x04
}
void pio_int(void) // 端口配置
{
XBR0=0x06
XBR1=0x40
P0MDIN=0xff //禁止模拟输入,0为模拟,1为数字
P0MDOUT=0x0d //0为开漏,1为推挽(ff)
P0SKIP=0x08
P1MDIN=0xff
P1MDOUT=0xff//低四位用于138
P1SKIP=0x00
P0=0xff
P1=0xff
}
/*************呈现各种显示效果的函数集****************/
//void Jump_Word(uchar a) 立即跳显示一个字或一张图案
//void M_Word(uchar a) 卷帘出显示一个字或一张图案
//void M_Words(number) 显示几个交换的字
//void UP_Run(number) 向上滚屏n个字
//void L_Removeout(number) 右入左出n个字
//void M_Black(void) 黑屏
//void R_Removeout(number) 左入右出n个字
/*****************************************************/
/****************立即跳显示一个字或一张图案***************/
void Jump_Word(uchar a)
{register uchar i,q
for(i=0i<32i++)
{
for(q=0q<BLKN/2q++)
{dispram[i+q*32]=Bmp[a][i]}
//if(i%2)delay(SPEED)
}
}
/****************卷帘出显示一个字或一张图案***************/
void M_Word(uchar a)
{register uchar i,q
for(i=0i<32i++)
{
for(q=0q<BLKN/2q++)
{dispram[i+q*32]=Bmp1[a][i]}
if(i%2)delay(SPEED)
}
}
/****************卷帘出显示number个字***************/
void M_Words(number)
{register uchar i,q,w
for(w=0w<number*2/BLKNw++)
{
for(i=0i<32i++)
{
for(q=0q<BLKN/2q++){dispram[i+q*32]=Bmp[q+w*BLKN/2][i]}
if(i%2)delay(SPEED)
}
delay(TIME)
}
}
/****************向上滚屏number个字***************/
void UP_Run(number)
{register uchar i,j,k,q
for(i=0i<number*2/BLKNi++)
{
for(j=0j<16j++)
{
for(k=0k<15k++)
{
for(q=0q<BLKN/2q++)
{
dispram[k*2+q*32]=dispram[(k+1)*2+q*32]
dispram[k*2+1+q*32]=dispram[(k+1)*2+1+q*32]
}
}
for(q=0q<BLKN/2q++)
{
dispram[30+q*32]=Bmp[q+i*BLKN/2][j*2]
dispram[31+q*32]=Bmp[q+i*BLKN/2][j*2+1]
}
delay(2*SPEED)
}
delay(2*TIME)
}
}
/****************左移出显示number个字*******************/
void L_Removeout(number)
{register uchar i,j,k,l,q
for(i=0i<numberi++)
{
for(j=0j<2j++)
for(k=0k<8k++)
{
for(l=0l<16l++)
{
for(q=0q<BLKN/2q++)
{
dispram[l*2+q*32]=dispram[l*2+q*32]<<1|dispram[l*2+1+q*32]>>7
if(q==BLKN/2-1)
dispram[l*2+1+q*32]=dispram[l*2+1+q*32]<<1|Bmp[i][l*2+j]>>(7-k)
else
dispram[l*2+1+q*32]=dispram[l*2+1+q*32]<<1|dispram[l*2+(q+1)*32]>>7
}
}
delay(2*SPEED)
}
}
}
/****************卷帘出黑屏***************/
void M_Black(void)
{register uchar i,q
for(i=0i<32i++)
{
for(q=0q<BLKN/2q++)
{dispram[i+q*32]=0x00}
if(i%2)delay(SPEED)
}
}
/****************右移出显示number个字*******************/
void R_Removeout(number)
{register uchar i,j,k,l,q
for(i=0i<numberi++)
{
for(j=2j>0j--)
for(k=0k<8k++)
{
for(l=0l<16l++)
{
for(q=0q<BLKN/2q++)
{
dispram[l*2+1+q*32]=dispram[l*2+1+q*32]>>1|dispram[l*2+q*32]<<7
if(q==0)
dispram[l*2+q*32]=dispram[l*2+q*32]>>1|Bmp[i][l*2+j-1]<<(7-k)
else
dispram[l*2+q*32]=dispram[l*2+q*32]>>1|dispram[l*2+1+(q-1)*32]<<7
}
}
delay(2*SPEED)
}
}
}
/*************用于时钟芯片 *** 作的函数集****************/
//void write_pcf8563(void)写时钟芯片
//void read_pcf8563(void)读时钟芯片
/*****************************************************/
void write_pcf8563(void)
{
SPI0CN &=~0x01//暂时关掉SPI通讯
send =0xa2 //送子器件地址
while(BUSY)
BUSY=1
SMB_RW=0control=5
STA=1 //开始传送
while(BUSY)
SPI0CN |=0x01//重新开启SPI
}
void read_pcf8563(void) //读当时的时,分,钞
{
SPI0CN &=~0x01
send =0xa2//送子器件地址
while(BUSY)
BUSY=1
SMB_RW=0
STA=1
send=0x02
while(!SI)
BUSY=1
send=0xa2
while(BUSY)
BUSY=1
SMB_RW=1
STA=1
while(BUSY)
BUSY=1
sec=receive1[2]&0x7f//读秒
min=receive1[1]&0x7f//读分
hou=receive1[0]&0x3f//读时
SPI0CN |=0x01
}
void spit_time(void)//分别计算时、分、秒的各位数字
{
sg=(int)hou/16
sd=(int)hou%16
fg=(int)min/16
fd=(int)min%16
mg=(int)sec/16
md=(int)sec%16
}
void dat_int(void) //数据初始化
{
scyx=1
CLK=0
}
void sysclk_int(void)
void delay(unsigned n)
void pio_int(void)
void SPI_INT(void)
void SMB_INT(void)
void dat_int(void)
void TIME01_INT(void)
void TIME2_INT(void)
void TIME3_INT(void)
void write_pcf8563(void)
void read_pcf8563(void)
void spit_time(void)
/**************主函数**************/
void main(void) //主程序
{
register uchar i
PCA0MD &= ~0x40// 关闭看门狗
sysclk_int()
OSCICN |= 0x02
/****************初始化检测pcf8563****************/
while(!pcf8563_sda)
{
XBR1 = 0x40
pcf8563_scl = 0
for(i = 0i <255i++)
pcf8563_scl = 1
while(!pcf8563_scl)
for(i = 0i <10i++)
XBR1 = 0x00
}
/****************初始化检测pcf8563****************/
pio_int()
TIME01_INT()
TIME2_INT()
TIME3_INT()
SPI_INT() //SPI0DAT是SPI的数据寄存
SMB_INT()
spit_time()
EIE1|=0x01
EA=1
dat_int()
led=0
TR0=0
delay(1000)
write_pcf8563()
while(1)
{
TR0=0
BUSY=0
read_pcf8563()
spit_time()
TR0=1
//Jump_Word(sg)
//Jump_Word(sd)
//Jump_Word(fg)
//Jump_Word(fd)
//Jump_Word(md)
//M_Word(md)
M_Word(4)
delay(10*TIME)
M_Words(TOTAL)
UP_Run(TOTAL)
M_Black()
delay(10*TIME)
L_Removeout(TOTAL)
delay(3*TIME)
M_Black()
delay(10*TIME)
R_Removeout(TOTAL)
delay(3*TIME)
}//总while循环的结束
}//main函数的结束
void t0(void) interrupt 1 //定时器0的中断服务程序
{
register uchar m,n=BLKN
TH0 = 0xfc
TL0 = 0x18
m = CONIO
m = (++m)&0x0f
for(n=0n<BLKNn++)
{
SPI0DAT = dispram[30-m*2+n]//dispram[((BLKN-)n/2+1)*30-m*2-(n/2)*30+n]
while(!SPIF)
SPIF=0
}
CONIO &= 0xf0
CLK = 1
CONIO |= m
CLK = 0
scyx=1
}
void SMBus_ISR (void) interrupt 7
{
bit FAIL = 0
if (ARBLOST == 0) //如果赢得总线
{
switch (SMB0CN &0xF0) //确定中断来源
{
case 0xe0://主发送方式下产生开始条件
SMB0DAT = send
SMB0DAT &= 0xFE
SMB0DAT |= SMB_RW //对发送的数据进行处理
STA = 0
break
case 0xc0://主方式下发送
if (ACK)
{
if (SMB_RW == 0)
{
if(send_number<=3)
{
if(control==0)
{
SMB0DAT = send
send_number+=5
}
else
{
SMB0DAT = send1[send_number]
send_number++
}
}
else
{
send_number=0control=0
STO = 1
BUSY = 0
}
}
else {} //BUSY=0
}
else
{
STO = 1
STA = 1
}
break
case 0x80://主方式下接收
if (receive_number-1>0) //控制接收3个数据就结束
{
receive1[receive_number-1] = SMB0DAT
ACK = 1
receive_number--
}
else
{
receive1[receive_number-1] = SMB0DAT
receive_number=3
BUSY = 0
ACK = 0
STO = 1
}
break
default:
FAIL = 1
break
}
}
else //输掉总线
{
FAIL = 1
}
if (FAIL) //SMBUS通讯失败后的处理
{
SMB0CF &= ~0x80
SMB0CF |= 0x80
STA = 0
STO = 0
ACK = 0
BUSY = 0
FAIL = 0
}
SI = 0
}
void T3_ISR() interrupt 14 //定时器3中断服务程序 用于检测SMBus是否超时
{
SMB0CF &= ~0x80
SMB0CF |= 0x80
TMR3CN &=~0x80
STA = 0
BUSY = 0
pcf8563_scl=1
}
怕有些地方你不知道是怎么来的,所有我就把完整的程序都给你了。你自己取出你所需要的就好了。因为不同的显示效果还是得靠住函数来实现的。
如果住函数没有写好,那么你的移动方式的函数就很难写了的。希望能给楼主一点灵感。呵呵~
我还有几种效果的,但是所有的效果都必须基于我的那种显示方式。你仔细看下,和你的是不是一样的,显示缓存,各种动画效果就是移动的控制方式了
给你借鉴一下,具体的呢还得根据你的硬件来了。
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define outdat P2
sbit ld=P3^0
sbit lw=P3^1
//数码管显示代码
unsigned char code tab[]={
0x01,0x02,0x03,0x04,0xFF,0xFF,0xFF,0xFF}
void delay1ms(unsigned int count) //延时1ms
{
unsigned char j
for(count>0count--)
for(j=0j<120j++)
}
void display(unsigned char num)
{
outdat=tab[num]
ld=0ld=1ld=0
outdat=0x01<<num
lw=0lw=1lw=0
delay1ms(2)
}
void main()
{
unsigned char i
while(1)
{
for(i=0i<8i++)
{
display(i)
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)