本帖最后由 JACK_1986 于 2011-6-28 16:30 编辑
向各位高手求助,三星9454,4位一体数码管,P2.0-P2.3控制个十百千位,P0.0-P0.6控制段位abcdefg,我现在的遇到的难题是能显示,但有明显的闪烁,内部0.5MHz,T0定时器fosc/4096分频,上图和程序 file:///d:/0-9999.bmp ,代码如下://********************************
//产品名称: IAR-C编程示例
//使用MCU: S3F9454
//FOSC = 0.5MHZ
//以下示例中很多变量及定义可能并未
//用到,在此仅仅作为示范性列示
//********************************
#include "ioS3C9454.h"//
#include "intrinsics.h"//包含内部函数
//************************************************
//**此处为宏定义替换******
//平台相关
#define SET_BIT(port, bit) (port = port | (0x1 << bit))
#define CLR_BIT(port, bit) (port = port & ~(0x1 << bit))
#define TEST_BIT(port, bit) (port & (0x1 << bit))
#define COM_BIT(port,bit) (port = port ^ (0x1 << bit))
#define NOP (__no_operation()) // 将后者指令行缩写为nop;
#define DI (__disable_interrupt()) //将后者指令行缩写为di;
#define EI (__enable_interrupt()) //将后者指令行缩写为ei;
//部分通用宏操作定义
#define Clr_WatchDog (BTCON |= 0x02) //喂狗
//************************************************
//**此处定义程序所用到的全局变量*******
unsigned char RUNFLAG = 0;
unsigned char DISPFLAG = 0;
unsigned char ERRFLAG = 0; //错误代码标志寄存器
unsigned char KEY_CODE = 0; //键扫描码
unsigned char table[10] ={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90}; //数码管
unsigned char tab_bit[4] = {0x1,0x2,0x4,0x8}; //p2.0-P2.3
unsigned int count;
unsigned char tp[4];
unsigned char num;
//*************************************************************************
//位操作寄存器定义
//*************************************************************************
//***程序所用函数声明*****
//***凡程序中所用到的函数请先在这里声明***
__interrupt void int_9454();
//*************************************************************************
//*************************************************************************
//**定义9454的SMART OPTION值****
//**003CH,must be initialized to 0
//**003DH,must be initialized to 0
//**003EH,enable LVR(2.3V)
//**003FH,internal RC(0.5MHZ in Vdd=5V)
//*************************************
__code const volatile unsigned char SmartOption[4] @0x003c = {0x0,0x0,0xe7,0x02};
//*************************************************************************
//*************************************************************************
**********************************************************
void Delay5ms(void) //延时函数
{
unsigned int i;
for(i=50;i>0;i--)
{
Clr_WatchDog;
NOP;
NOP;
NOP;
NOP;
NOP;
NOP;
NOP;
NOP;
NOP;
NOP;
}
}
void LedScan(unsigned char num,unsigned char wei)
{
//这里是LED显示动态扫描过程
P2=0x0;
P0=table[num]; //段码
P2=tab_bit[wei]; //位
Delay5ms(); //延时
P2=0x0; //关闭显示
}
//========================主程序控制===========================
void main(void)
{
unsigned char buffer = SmartOption[0];
BTCON= 0xA2;
CLKCON=0x98;
P0PND = 0x00;
//P0CONH=0x9a;//
P0CONH = 0xAA; //推挽输出
P0CONL = 0xAA; //推挽输出
P0 = 0x0;
P1CON = 0xCA;
P1 = 0x0;
P2CONH = 0x4A;
P2CONL = 0xAA;
P2=0x0;
PWMDATA = 0x80;
PWMCON = 0x10; //FOSC/64
//PWMCON = 0x4;
T0DATA = 0x7A; //1s
T0CON = 0x0A; //fosc/4096
EI;
while(1)
{
unsigned char i;
for(i=0;i<4;++i)
{
LedScan(tp,i); //显示
}
}
}
//******************************************************************
#pragma vector=0x00
__interrupt void int_9454()
{
T0CON = T0CON & 0xFE; //必须清T0中断标志
T0DATA=0x7A;
T0CON=0xA;
count++; //1s来一次中断
if(count>9999)
{
count=0;
}
tp[3]=count/1000; //千位
tp[2]=count%1000/100; //百位
tp[1]=count%100/10; //十位
tp[0]=count%10; //个位
}
//*************************************************************************
|