本帖最后由 如果 于 2012-6-20 13:41 编辑
为什么时钟不会跑 求大神指点啊
- #include <stc11.h>
- #include <stdio.h>
- #include <intrins.h>
- #define BIAS 0X52 //1/3偏压,4背极
- #define RC256K 0X38 //系统时钟选择为片外RC振荡器
- #define WDTDIS1 0X0A //禁止WDT溢出标志输出
- #define TIMERDIS 0X08 //时基输出禁止
- #define SYSEN 0X02 //打开系统时钟
- #define SYSDIS 0X00 //关闭系统时钟和偏压发生器
- #define LCDON 0X06 //打开LCD偏压发生器
- #define LCDOFF 0X04 //关闭LCD偏压发生器
- #define TONEON 0X12 //打开音频输出
- #define TONEOFF 0X10 //关闭音频输出
- sbit CS=P2^0;
- sbit WRD=P2^2;
- sbit DATA=P2^3;
- sbit LED=P2^1;
- sbit speak=P1^4;
- #define uchar unsigned char
- #define uint unsigned int
- char tab[]={0x5f,0x06,0x6b,0x2f,0x36,0x3d,0x7d,0x07,0x7f,0x3f}; //显示0—9
- char x,sec,min,hour,shi;
- uchar a[16];
- /***************************延时子函数******************************/
- void delay(uchar i) //j=12延时约4.3us
- {
- while(i--)
- {
- uchar j=0;
- while(j<8)
- j++;
- }
- }
- void delay_1s()
- {unsigned int i,j,k;
- for(i=100;i>0;i--)
- for(j=20;j>0;j--)
- for(k=248;k>0;k--);
- }
- void delay_ms(int x) //延时毫秒
- {
- int i;
- while(x--)
- {
- for(i=0;i<100;i++);
-
- }
- }
- void SendBit_1621(uchar dat ,uchar cnt)
- {
- uchar i;
- for(i =0; i <cnt; i ++)
- {
- if((dat&0x80)==0)
- DATA=0;
- else
- DATA=1;
- WRD=0;
- delay(2);
- WRD=1;
- dat=dat<<1;
- }
- }
- void SendDataBit_1621(uchar dat,uchar cnt)
- {
- uchar i;
- for(i =0; i <cnt; i ++)
- {
- if((dat&0x01)==0) DATA=0;
- else DATA=1;
- WRD=0;
- delay(2);
- WRD=1;
- dat=dat>>1;
- }
- }
- void SendCmd(uchar command)
- {
- CS=0;
- _nop_();
- _nop_();
- SendBit_1621(0x80,4);
- SendBit_1621(command,8);
- CS=1;
- }
- void Write_1621(uchar addr,uchar dat)
- {
- CS=0;
- _nop_();
- _nop_();
- SendBit_1621(0xa0,3);
- SendBit_1621(addr,6);
- SendDataBit_1621(dat,4);
- CS=1;
- }
- void WriteAll_1621(uchar addr,uchar *p,uchar cnt)
- {
- uchar i;
- CS=0;
- _nop_();
- _nop_();
- SendBit_1621(0xa0,3);
- SendBit_1621(addr,6);
- for(i =0; i <cnt; i ++,p++)
- {
- SendDataBit_1621(*p,8);
- }
- CS=1;
- }
- /*******************************主函数******************************/
- main()
- {
-
- //a[0]=0x00;a[1]=0x00;a[2]=0x00;a[3]=0x00;a[4]=0x00;
- //a[5]=0x00;a[6]=0x00;a[7]=0x00;a[8]=0x00;
- //a[9]=0x5F;a[10]=0x5F;a[11]=0x5F;a[12]=0x5F;
- //a[13]=0x00;a[14]=0x00;a[15]=0x00;
- speak=1;
-
- TMOD=0x01;
- ET0=1;
- EA=1;
- TH0=(65535-10000)/256;
- TL0=(65535-10000)%256;
- TR0=1;
- SendCmd(BIAS);
- SendCmd(SYSEN);
- SendCmd(LCDON);
- // SendCmd(RC256K);
- WriteAll_1621(0,a,16);
- // SendCmd(LCDOFF);
- while(1)
- {
- /*speak=0;
- delay_1s();
- speak=1;
- delay_1s();*/
- a[12]=tab[min%10]; //显示分个位
- delay_ms(2);
- a[11]=tab[min/10]; //显示分十位
- delay_ms(2);
- a[10]=tab[hour%10]; //显示时个位
- delay_ms(2);
- a[9]=tab[(hour/10)|0x80]; //显示时十位
- delay_ms(2);
-
- }
-
-
-
- }
- void int0() interrupt 1
- {
- //uchar a[16];
- TH0=(65535-10000)/256;
- TL0=(65535-10000)%256; //定时10ms
- x++;
- shi++;
- if(shi>=50)
- {
- shi=0;
- //a[11]=0x80;
- //a[10]=0x80;
- }
- if(x>=100) //表示1S
- {
- x=0;
- sec++;
- if(sec==60) //到60秒,秒清零,分加一
- {
- sec=0;
- min++;
- if(min==60) //到60分,分清零,小时加一
- {
- min=0;
- hour++;
- /*speak=0;
- delay_1s();
- speak=1;
- delay_1s();*/
- if(hour==24) //到24时,时清零,也是所有清零
- {
- hour=0;
- }
- }
- }
- }
- }
复制代码程序调试不出来,没显示
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
可惜看不懂C。。。。。。。。。。
#if FREQUENCY > 8000
#define SOFT_DELAY 10
#endif
//void Delay(uint16_t n);
/******************************************************************************
写入数据的位
每次写入数据 1 -- 8 位
数据在时钟上升沿写入
******************************************************************************/
void HT1621_Write_Nbit (uint8_t data,uint8_t nbit)
{
uint8_t i;
for (i=0;i<nbit;i++)
{
HT1621_WR_CLR(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
if (data&0x80) // if the bit is 1, write 1
{
HT1621_DATA_SET() ; // write 1
}
else
{
HT1621_DATA_CLR(); // write 0
}
data <<= 1;
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
}
}
/******************************************************************************
写入 31 个 RAM 中任意一个地址半个字节
******************************************************************************/
void HT1621_Write_4bit (uint8_t dadd,uint8_t dbyte)
{
dadd <<= 2;
HT1621_CS_SET(); // chip disable
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_CS_CLR(); // chip select
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_Write_Nbit (0xA0,3); // command of write data
HT1621_Write_Nbit (dadd,6); // address of ram
HT1621_Write_Nbit (dbyte,4); // data of display
HT1621_CS_SET();
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
}
/******************************************************************************
写入数据的位
每次写入数据 1 -- 8 位
数据在时钟上升沿写入
******************************************************************************/
uint8_t HT1621_Read_4bit (void)
{
uint8_t i;
uint8_t data;
data = 0;
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
for (i = 0;i < 4;i++)
{
HT1621_RD_CLR(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
if (HT1621_READ_DATA()) // if the bit is 1, write 1
{
data |= 1<<i; // write 1
}
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_RD_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
}
return data;
}
/*******************************************************************************
写入 32 个 RAM 中任意一个地址一个字节
*******************************************************************************/
void HT1621_Write_Byte_To_Ram (uint8_t dadd,uint8_t dbyte)
{
dadd <<= 2;
HT1621_CS_SET(); // chip disable
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_CS_CLR(); // chip select
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_Write_Nbit (0xA0,3); // command of write data
HT1621_Write_Nbit (dadd,6); // address of ram
HT1621_Write_Nbit (dbyte,8); // data of display
HT1621_CS_SET();
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
}
/*******************************************************************************
写入全部 RAM 数据
*******************************************************************************/
void HT1621_Write_All_Data_to_Ram (uint8_t *dbyte)
{
uint8_t i;
HT1621_CS_SET(); // chip disable
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_CS_CLR(); // chip select
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_Write_Nbit (0xA0,3); // command of write data
HT1621_Write_Nbit (0,6); // address of ram
for (i = 0; i < 32;i++)
{
HT1621_Write_Nbit (dbyte[i],4); // data of display
}
HT1621_CS_SET();
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
}
/*******************************************************************************
写入全部 RAM 数据
*******************************************************************************/
void HT1621_Write_All_Data_to_Ram_Not_Continuous (uint8_t *dbyte,uint8_t index)
{
HT1621_CS_SET(); // chip disable
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_CS_CLR(); // chip select
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
if (index == 0)
{
HT1621_Write_Nbit (0xA0,3); // command of write data
HT1621_Write_Nbit (0,6); // address of ram
}
HT1621_Write_Nbit (dbyte[index],4); // data of display
HT1621_CS_SET();
HT1621_WR_SET(); // rising edge
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
}
/*******************************************************************************
写入命令
*******************************************************************************/
void HT1621_Write_Command (uint8_t dcommand)
{
HT1621_CS_SET();
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_CS_CLR();
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
HT1621_Write_Nbit (0x80,4);
HT1621_Write_Nbit (dcommand,8);
HT1621_CS_SET();
#ifdef SOFT_DELAY
Delay(SOFT_DELAY);
#endif
}
/*******************************************************************************
初始化
*******************************************************************************/
void HT1621_Init (void)
{
HT1621_Write_Command(HT1621_LCD_OFF);
HT1621_Write_Command(HT1621_RC256K);
HT1621_Write_Command(HT1621_TONE_OFF);
// 设置蜂鸣器频率
HT1621_Write_Command(HT1621_TONE_4K);
HT1621_Write_Command(HT1621_TONE_ON);
// 关闭蜂鸣器输出
HT1621_Write_Command(HT1621_BIAS_DUTY); //
HT1621_Write_Command(HT1621_SYS_EN);
HT1621_Write_Command(HT1621_LCD_ON);
}
#define _HT1621_H_
/* PORT CONFIG */
#define HT1621_DDR
#define HT1621_CS_SET() (GPIOC->ODR |= GPIO_Pin_9)
#define HT1621_CS_CLR() (GPIOC->ODR &= (~GPIO_Pin_9))
#define HT1621_WR_SET() (GPIOC->ODR |= GPIO_Pin_7)
#define HT1621_WR_CLR() (GPIOC->ODR &= (~GPIO_Pin_7))
#define HT1621_RD_SET() (GPIOC->ODR |= GPIO_Pin_8)
#define HT1621_RD_CLR() (GPIOC->ODR &= (~GPIO_Pin_8))
#define HT1621_DATA_SET() (GPIOC->ODR |= GPIO_Pin_6)
#define HT1621_DATA_CLR() (GPIOC->ODR &= ~GPIO_Pin_6)
#define HT1621_READ_DATA() ((GPIOC->IDR&GPIO_Pin_6))
/* LCD COMMAND */
#define HT1621_LCD_ON 0x06
#define HT1621_LCD_OFF 0x04
#define HT1621_TIMER_DIS 0x08
#define HT1621_WDT_DIS 0x0a
#define HT1621_SYS_EN 0x02
#define HT1621_TONE_OFF 0x10
#define HT1621_TONE_ON 0x12
#define HT1621_TONE_4K 0x40
#define HT1621_TONE_2K 0x60
#define HT1621_RC256K 0x30
#define HT1621_BIAS_DUTY 0x52
#define HT1621_IRQ_DIS 0x00
/* LCD */
#define LCD_ON 1
#define LCD_OFF 0
typedef struct
{
uint8_t buff[32];
} HT1621_TypeDef;
//extern HT1621_TypeDef HT1621;
void HT1621_Write_Nbit (uint8_t data,uint8_t nbit);
void HT1621_Write_4bit (uint8_t dadd,uint8_t dbyte);
uint8_t HT1621_Read_4bit (void);
void HT1621_Write_Byte_To_Ram (uint8_t dadd,uint8_t dbyte);
void HT1621_Write_All_Data_to_Ram (uint8_t *dbyte);
void HT1621_Write_Command (uint8_t dcommand);
void HT1621_Init (void);
void HT1621_Write_All_Data_to_Ram_Not_Continuous (uint8_t *dbyte,uint8_t index);
#endif
一周热门 更多>