本帖最后由 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编译是能通过的,求原因
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
//#include "stc15f104e.h"
//#include "STC15.h"
#include "codetab.h"
sbit LCD_SCL=P3^0; //时钟 D0(SCLK)
sbit LCD_SDA=P3^1; //D1(MOSI) 数据
sbit LCD_RST=P3^2; //复位
sbit LCD_DC =P3^3; //数据/命令控制
#define XLevelL 0x00
#define XLevelH 0x10
#define XLevel ((XLevelH&0x0F)*16+XLevelL)
#define Max_Column 128
#define Max_Row 64
#define Brightness 0xCF
#define X_WIDTH 128
#define Y_WIDTH 64
/*********************LCD 延时1ms************************************/
void LCD_DLY_ms(unsigned int ms)
{
unsigned char a,b;
while(ms--)
{ for(b=222;b>0;b--)
for(a=12;a>0;a--);
}
return;
}
/*********************LCD写数据************************************/
void LCD_WrDat(unsigned char dat)
{
unsigned char i;
LCD_DC=1;
for(i=0;i<8;i++) //发送一个八位数据
{
if((dat << i) & 0x80)
{LCD_SDA = 1;}
else LCD_SDA = 0;
LCD_SCL = 0;
LCD_SCL = 1;
}
}
/*********************LCD写命令************************************/
void LCD_WrCmd(unsigned char cmd)
{
unsigned char i;
LCD_DC=0;
for(i=0;i<8;i++) //发送一个八位数据
{
if((cmd << i) & 0x80)
{LCD_SDA = 1;}
else LCD_SDA = 0;
LCD_SCL = 0;
LCD_SCL = 1;
}
}
/*********************LCD 设置坐标************************************/
void LCD_Set_Pos(unsigned char x, unsigned char y)
{
LCD_WrCmd(0xb0+y);
LCD_WrCmd(((x&0xf0)>>4)|0x10);
LCD_WrCmd((x&0x0f)|0x01);
}
/*********************LCD全屏************************************/
void LCD_Fill(unsigned char bmp_dat)
{
unsigned char y,x;
for(y=0;y<8;y++)
{
LCD_WrCmd(0xb0+y);
LCD_WrCmd(0x01);
LCD_WrCmd(0x10);
for(x=0;x<X_WIDTH;x++)
LCD_WrDat(bmp_dat);
}
}
/*********************LCD复位************************************/
void LCD_CLS(void)
{
unsigned char y,x;
for(y=0;y<8;y++)
{
LCD_WrCmd(0xb0+y);
LCD_WrCmd(0x01);
LCD_WrCmd(0x10);
for(x=0;x<X_WIDTH;x++)
LCD_WrDat(0);
}
}
/*********************LCD初始化************************************/
void LCD_Init(void)
{
LCD_SCL=1;
LCD_RST=0;
LCD_DLY_ms(50);
LCD_RST=1; //从上电到下面开始初始化要有足够的时间,即等待RC复位完毕
LCD_WrCmd(0xae);//--turn off oled panel
LCD_WrCmd(0x00);//---set low column address
LCD_WrCmd(0x10);//---set high column address
LCD_WrCmd(0x40);//--set start line address Set Mapping RAM Display Start Line (0x00~0x3F)
LCD_WrCmd(0x81);//--set contrast control register
LCD_WrCmd(0xcf); // Set SEG Output Current Brightness
LCD_WrCmd(0xa1);//--Set SEG/Column Mapping 0xa0左右反置 0xa1正常
LCD_WrCmd(0xc8);//Set COM/Row Scan Direction 0xc0上下反置 0xc8正常
LCD_WrCmd(0xa6);//--set normal display
LCD_WrCmd(0xa8);//--set multiplex ratio(1 to 64)
LCD_WrCmd(0x3f);//--1/64 duty
LCD_WrCmd(0xd3);//-set display offset Shift Mapping RAM Counter (0x00~0x3F)
LCD_WrCmd(0x00);//-not offset
LCD_WrCmd(0xd5);//--set display clock divide ratio/oscillator frequency
LCD_WrCmd(0x80);//--set divide ratio, Set Clock as 100 Frames/Sec
LCD_WrCmd(0xd9);//--set pre-charge period
LCD_WrCmd(0xf1);//Set Pre-Charge as 15 Clocks & Discharge as 1 Clock
LCD_WrCmd(0xda);//--set com pins hardware configuration
LCD_WrCmd(0x12);
LCD_WrCmd(0xdb);//--set vcomh
LCD_WrCmd(0x40);//Set VCOM Deselect Level
LCD_WrCmd(0x20);//-Set Page Addressing Mode (0x00/0x01/0x02)
LCD_WrCmd(0x02);//
LCD_WrCmd(0x8d);//--set Charge Pump enable/disable
LCD_WrCmd(0x14);//--set(0x10) disable
LCD_WrCmd(0xa4);// Disable Entire Display On (0xa4/0xa5)
LCD_WrCmd(0xa6);// Disable Inverse Display On (0xa6/a7)
LCD_WrCmd(0xaf);//--turn on oled panel
LCD_Fill(0x00); //初始清屏
LCD_Set_Pos(0,0);
}
/***************功能描述:显示6*8一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
/*void LCD_P6x8Str(unsigned char x, y,unsigned char ch[])
{
unsigned char c=0,i=0,j=0;
while (ch[j]!=' ')
{
c =ch[j]-32;
if(x>126){x=0;y++;}
LCD_Set_Pos(x,y);
for(i=0;i<6;i++)
LCD_WrDat(F6x8[c][i]);
x+=6;
j++;
}
}
/*******************功能描述:显示8*16一组标准ASCII字符串 显示的坐标(x,y),y为页范围0~7****************/
void LCD_P8x16Str(unsigned char x, y,unsigned char ch[])
{
unsigned char c=0,i=0,j=0;
while (ch[j]!=' ')
{
c =ch[j]-32;
if(x>120){x=0;y++;}
LCD_Set_Pos(x,y);
for(i=0;i<8;i++)
LCD_WrDat(F8X16[c*16+i]);
LCD_Set_Pos(x,y+1);
for(i=0;i<8;i++)
LCD_WrDat(F8X16[c*16+i+8]);
x+=8;
j++;
}
}
/*****************功能描述:显示16*16点阵 显示的坐标(x,y),y为页范围0~7****************************/
void LCD_P16x16Ch(unsigned char x, y, N)
{
unsigned char wm=0;
unsigned int adder=32*N; //
LCD_Set_Pos(x , y);
for(wm = 0;wm < 16;wm++) //
{
LCD_WrDat(F16x16[adder]);
adder += 1;
}
LCD_Set_Pos(x,y + 1);
for(wm = 0;wm < 16;wm++) //
{
LCD_WrDat(F16x16[adder]);
adder += 1;
}
}
/*****************功能描述:显示16*32点阵 显示的坐标(x,y),y为页范围0~3****************************/
void LCD_P16x32Ch(unsigned char x, y, N)
{
unsigned char wm=0;
unsigned int adder=64*N; //
LCD_Set_Pos(x , y);
for(wm = 0;wm <32;wm++) //
{
LCD_WrDat(F16x32[adder]);
adder += 1;
}
LCD_Set_Pos(x,y + 1);
for(wm = 0;wm < 32;wm++) //
{
LCD_WrDat(F16x32[adder]);
adder += 1;
}
}
/***********功能描述:显示显示BMP图片128×64起始点坐标(x,y),x的范围0~127,y为页的范围0~7*****************/
/*void Draw_BMP(unsigned char x0, y0,x1, y1,unsigned char BMP[])
{
unsigned int j=0;
unsigned char x,y;
if(y1%8==0) y=y1/8;
else y=y1/8+1;
for(y=y0;y<y1;y++)
{
LCD_Set_Pos(x0,y);
for(x=x0;x<x1;x++)
{
LCD_WrDat(BMP[j++]);
}
}
}
这个OLED的驱动程序,是淘宝商家提供的,.H里面确实包含了程序,不过我单独测试OLED驱动的时候,没有错误没有警告,硬件也能正常驱动的。
另外,我直接把OLED的驱动.H改成.C可以吗?
一周热门 更多>