本帖最后由 madswan 于 2013-3-12 16:09 编辑
我原来的程序前面是这样的:
#include "STC15.H"
#include "intrins.h"
//#include "LQ12864.h"
#include "codetab.h"
#define On 1
#define Off 0
unsigned char Led_TimeCount ;
unsigned char Timer0_5Ms ;
unsigned char TIME_MM;
unsigned char TIME_SS;
unsigned char TIME_MM1;
unsigned char TIME_SS1 ;//预设时间值
sbit Led = P3^5 ; //用于秒闪烁
sbit Relay = P3^4 ; //用于继电器吸合及释放
bit Timer0_1S_Flag ;
/*******************************************************************/
void Timer0_Init(void) //5毫秒@12.000MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式( 16位自动重装 )
TL0 = 0xA0; //设置定时初值
TH0 = 0x15; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
ET0 = 1;
EA = 1;
TIME_MM=12;
TIME_SS=45;
}
void Timer0_Isr(void) interrupt 1 using 0
{
if ( ++Timer0_5Ms>= 200 )
{
Timer0_5Ms = 0 ;
Timer0_1S_Flag = 1 ;
Led = On ;
}
if ( Led )
{
Led_TimeCount++ ;
if ( Led_TimeCount >=10 )
{
Led_TimeCount = 0 ;
Led = Off ;
}
}
}
void main (void)
{
unsigned int Second ;
unsigned char Hour ;
unsigned char Relay_TimeCount ;
Relay = Led = Off ;
Timer0_Init();
while(1)
{
if ( Timer0_1S_Flag )
{
Timer0_1S_Flag = 0 ;
if ( Relay ) //如果继电器打开
{
Relay_TimeCount++ ;
if ( Relay_TimeCount >= 3 )
{
Relay_TimeCount = 0 ;
Relay = Off ;
}
}
if ( ++Second>=3600 ) //如果满1小时
{
Second = 0 ;
Hour++;
if ( Hour >= 9 )
{
Hour = 0 ;
Relay = On ;
}
}
}
}
}
把“#include"LQ12864.h"屏蔽掉,程序编译通过,无错误和警告;
把这句#include加上之后(LQ12864.h是一个OLED屏幕的驱动),就编译不过了
出现如下一串错误
clock.c(31): error C202: 'TIME_MM': undefined identifier
clock.c(32): error C202: 'TIME_SS': undefined identifier
clock.c(37): error C202: 'Timer0_5Ms': undefined identifier
clock.c(39): error C202: 'Timer0_5Ms': undefined identifier
clock.c(40): error C202: 'Timer0_1S_Flag': undefined identifier
clock.c(41): error C202: 'Led': undefined identifier
clock.c(43): error C202: 'Led': undefined identifier
clock.c(45): error C202: 'Led_TimeCount': undefined identifier
clock.c(46): error C202: 'Led_TimeCount': undefined identifier
clock.c(48): error C202: 'Led_TimeCount': undefined identifier
clock.c(49): error C202: 'Led': undefined identifier
clock.c(59): error C202: 'Relay': undefined identifier
clock.c(63): error C202: 'Timer0_1S_Flag': undefined identifier
clock.c(65): error C202: 'Timer0_1S_Flag': undefined identifier
clock.c(66): error C202: 'Relay': undefined identifier
clock.c(72): error C202: 'Relay': undefined identifier
clock.c(82): error C202: 'Relay': undefined identifier
Target not created
照理这些都在开头定义了的,而且去掉LQ12864.H编译是能通过的,求原因
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
LZ对前后台系统了解么?
可以搜一下“时钟触发嵌入式系统设计模式”
再看看:从单片机初学者迈向单片机工程师 的帖子
论坛里面都有的。看了以后就大概知道该怎么设计这个OLED时钟了。
每秒都要刷新,刷新时间应该小于1S,每秒刷新两次就可以了。
液晶屏的刷新显示动作应该放在主程序中。
定义全局变量gTimer_tick,利用定时器产生10ms的中断,在定时器中断里只将gTimer_tick置1。
然后在mian()程序里对gTimer_tick进行判断。可进行如下判断:
if(1==gTimer_tick)
{
gTimer_tick = 0;
gTime_1S ++; //全局变量,相当于软件定时器,定时1S
gTime_0.5S ++; //软件定时器,定时0.5S
…………//同理,可以设置很多定时器,定不同的时间,就跟定闹铃一样。
}
//判断时间是否过了1S。
if( gTime_1S=100 ) //10ms*100=1S
{
gTime_1S=0;
……………………//干1S间隔该干的事
}
if( gTime_0.5S=50 ) //10ms*50=0.5S
{
gTime_0.5S=0;
……………………//干0.5间隔该干的事
}
一周热门 更多>