本帖最后由 芯圣电子官方QQ 于 2023-7-25 14:34 编辑
先上全家福,仿真器,开发板,还有芯片5个!!
接下来用原来开发的产品上8位数码管,两片74HC595级联,仿真器调试模式
不知道为什么图片上传后方向会变
下面是代码
#include "HC89F003.h"
#define u8 unsigned char
#define u16 unsigned int
#define u32 unsigned long
sbit RCLK = P0^0;
u8 xs,miao;
u32 hm;
u8 code LED[] = {0x0A,0xFA,0x8C,0xA8,0x78,0x29,0x09,0xBA,0x08,0x28,0x00};//0-9,-
void LED_OUT(u8 X)
{
SPDAT=X;
while((SPSTAT&0x80)==0x00); //查询SPI传输是否完成
SPSTAT=0xf0; //写1清除所有标志
}
void Timer3init(void)
{
T3CON =0x00;
TH3=(65536-8000)/256;
TL3=(65536-8000)%256;
ET3=1;
T3CON |= 0x04;
}
void display(void)
{
u8 bai,shi,ge,a1,a2,a3,a4,a5;
bai=hm%100000000/10000000;
shi=hm%10000000/1000000;
ge=hm%1000000/100000;
a1=hm%100000/10000;
a2=hm%10000/1000;
a3=hm%1000/100;
a4=hm%100/10;
a5=hm%10;
switch(xs)
{
case 0:
LED_OUT(0x20); //位选数据
LED_OUT(LED[bai]); //段选数据
RCLK = 0; RCLK = 1;
xs=1;
break;
case 1:
LED_OUT(0x02);
LED_OUT(LED[shi]);
RCLK = 0; RCLK = 1;
xs=2;
break;
case 2:
LED_OUT(0x04);
LED_OUT(LED[ge]);
RCLK = 0; RCLK = 1;
xs=3;
break;
case 3:
LED_OUT(0x08);
LED_OUT(LED[a1]);
RCLK = 0; RCLK = 1;
xs=4;
break;
case 4:
LED_OUT(0x01);
LED_OUT(LED[a2]);
RCLK = 0; RCLK = 1;
xs=5;
break;
case 5:
LED_OUT(0x40);
LED_OUT(LED[a3]);
RCLK = 0; RCLK = 1;
xs=6;
break;
case 6:
LED_OUT(0x80);
LED_OUT(LED[a4]);
RCLK = 0; RCLK = 1;
xs=7;
break;
case 7:
LED_OUT(0x10);
LED_OUT(LED[a5]);
RCLK = 0; RCLK = 1;
xs=0;
break;
}
}
void Init(void)
{
WDTCCR = 0x00; //关闭看门狗
while((CLKCON&0x20)!=0x20); //等待内部高频晶振起振
CLKSWR = 0x53; //选择内部高频时钟为主时钟,内部高频RC 8分频,Fosc=4MHz
while((CLKSWR&0xC0)!=0x40); //等待内部高频切换完成
CLKDIV = 0x00; //Fosc 0分频得到Fcpu,Fcpu=4MHz
}
void SPI_Init(void)
{
P0M0=0x88; //P00 P01推挽输出
P0M1=0x08; //P02推挽输出 P03输入
SCK_MAP=0x01; //SPI_SCK脚映射至P01上
MOSI_MAP=0x02; //SPI_MOSI脚映射至P02上
// MISO_MAP=0x03; //74HC595用不到MISO
SPCTL=0xdf; //SPI设置
}
int main (void)
{
Init();
Timer3init();
SPI_Init();
EA=1;
while(1);
}
void Timer3_ISR (void) interrupt 9
{
display();
hm++;
}
最后说说这芯片的外设管脚的映射功能真强大,大大方便开发了还有不用库的话最好换个头文件,自带的不太好用好像,附件随便提供头文件
HC89F003.rar
(6.79 KB)
|