本人做了个光源,遇到疑问请各位高手不吝赐教。此光源采用PWM调光,采用STC12CLE5A48S2单片机,LCD显示LED光源的亮度,定时器1作为串口波特率发生器,定时器0用来产生PWM方波。程序在不加EEPROM读写子程序,光源能正常通过按键进行调光,但是在加了EEPROM读写子程序,在有调光按键按下时,光源都会产生闪烁。听别人说,是EEPROM子程序和其他程序在占用硬件上有冲突,但是还是不懂,不知道哪边有冲突。麻烦高手指点一下,谢谢喽。如果需要程序我可以把程序附上,如果我有什么说不清楚的地方,请指出了,我可以详细再说下。再谢。
此帖出自
小平头技术问答
uchar reverse(figure) //反转P0口
{
uchar a=0;
uchar j,b;
for(j=0;j<8;j++)
{
a=a>>1;
b=figure&0x80;
if(b!=0)
{
a=a|0x80;
}
figure=figure<<1;
}
return a;
}
void CmdWrite(uchar cam_data) //写地址
{
uchar CAMDATA;
CAMDATA=reverse(cam_data);
CS1=1;
A0=0;
CS1=0;
RD=1;
WR=0;
databus=CAMDATA;
WR=1;
CS1=1;
}
void DataWrite(uchar data_data) //写数据
{
CS1=1;
A0=1;
CS1=0;
RD=1;
WR=0;
databus=data_data;
WR=1;
CS1=1;
}
void NT75451_INIT(void) //128*64液晶屏初始化
{
Delay(100);
CmdWrite(0xE2); //STANDBY MODE OFF
Delay(40);
//CmdWrite(0x34);
CmdWrite(0xA2); //bias set 1/9,1/65 DUTY ,亮度设置
CmdWrite(0xA0); //ADC select SEG0 to SEG127 normal
CmdWrite(0xC8); //COM Reverse
CmdWrite(0x40); //Display Start Line Set =0
Delay(20);
CmdWrite(0x25); //V0 Voltage Regulator Internal Resistor Ratio Set
CmdWrite(0x2f); //power control(VC,VR,VF=1,1,1)(028--02FH)--2f
Delay(20);
CmdWrite(0x81); //Regulator resistor select 100(020H--027H)
CmdWrite(CTRL); //contrast
Delay(20);
//CmdWrite(0x00); //Initial Display Line/Number of Start Line Set-63-3F
CmdWrite(0xA6);
CmdWrite(0x89); //Select DC-DC converter circuit
CmdWrite(0x01); //4 times boosting circuit
CmdWrite(0xE5); //Oscillation Frequency Select-31.4KHZ
CmdWrite(0xA4); //Entire Display ON
CmdWrite(0xAf); //turns the display ON
Delay(100);
contrast = CTRL;
}
void LCD_Reset(void)
{
// RES=1;
// DelayXms(2);
RES=0;
Delay(200);
RES=1;
Delay(200);//more than 150ms
}
void clear(void) //清屏
{
uint i,j;
for(i=0;i<8;i++)
{
CmdWrite(i+0xb0); //行地址
CmdWrite(0x10); //列地址
CmdWrite(0x00); //此指令是为了列地址能够自动递加
for(j=0;j<128;j++)
{
DataWrite(0x00);
}
}
}
void display_WORD(uchar row,uchar line,uchar *character) //写汉字
{
uchar j;
CmdWrite(0xb0+row); //行
CmdWrite(0x10+line); //列
CmdWrite(0x00);
for(j=0;j<16;j++)
{
DataWrite(character[j]);
}
CmdWrite(0xb1+row); //行
CmdWrite(0x10+line); //列
CmdWrite(0x00);
for(j=16;j<32;j++)
{
DataWrite(character[j]);
}
}
void display_digit(uchar value) //写数字
{
uchar j,l,m,n;
if(value>=100)
{
value=100;
}
l=value/100;
m=value%100/10;
n=value%100%10;
if(l==0)
{
if(m==0)
{
CmdWrite(0xb3);
CmdWrite(0x13);
CmdWrite(0x00);
for(j=0;j<8;j++) {DataWrite(0x00);}
for(j=0;j<8;j++) {DataWrite(0x00);}
for(j=0;j<8;j++) {DataWrite(digit[n*16+j]);}
for(j=0;j<8;j++) {DataWrite(fenhao[j]);}
for(j=0;j<8;j++) {DataWrite(0x00);}
CmdWrite(0xb4);
CmdWrite(0x13);
CmdWrite(0x00);
for(j=8;j<16;j++) {DataWrite(0x00);}
for(j=8;j<16;j++) {DataWrite(0x00);}
for(j=8;j<16;j++) {DataWrite(digit[n*16+j]);}
for(j=8;j<16;j++) {DataWrite(fenhao[j]);}
for(j=8;j<16;j++) {DataWrite(0x00);}
}
else
{
CmdWrite(0xb3);
CmdWrite(0x13);
CmdWrite(0x00);
for(j=0;j<8;j++) {DataWrite(0x00);}
for(j=0;j<8;j++) {DataWrite(digit[m*16+j]);}
for(j=0;j<8;j++) {DataWrite(digit[n*16+j]);}
for(j=0;j<8;j++) {DataWrite(fenhao[j]);}
for(j=0;j<8;j++) {DataWrite(0x00);}
CmdWrite(0xb4);
CmdWrite(0x13);
CmdWrite(0x00);
for(j=8;j<16;j++) {DataWrite(0x00);}
for(j=8;j<16;j++) {DataWrite(digit[m*16+j]);}
for(j=8;j<16;j++) {DataWrite(digit[n*16+j]);}
for(j=8;j<16;j++) {DataWrite(fenhao[j]);}
for(j=8;j<16;j++) {DataWrite(0x00);}
}
}
else
{
CmdWrite(0xb3);
CmdWrite(0x13);
CmdWrite(0x00);
for(j=0;j<8;j++) {DataWrite(digit[16+j]);}
for(j=0;j<8;j++) {DataWrite(digit[m*16+j]);}
for(j=0;j<8;j++) {DataWrite(digit[n*16+j]);}
for(j=0;j<8;j++) {DataWrite(fenhao[j]);}
for(j=0;j<8;j++) {DataWrite(0x00);}
CmdWrite(0xb4);
CmdWrite(0x13);
CmdWrite(0x00);
for(j=8;j<16;j++) {DataWrite(digit[16+j]);}
for(j=8;j<16;j++) {DataWrite(digit[m*16+j]);}
for(j=8;j<16;j++) {DataWrite(digit[n*16+j]);}
for(j=8;j<16;j++) {DataWrite(fenhao[j]);}
for(j=8;j<16;j++) {DataWrite(0x00);}
}
}
void guangzhu (uchar value) //显示柱状图
{
uchar j;
CmdWrite(0xb2);
CmdWrite(0x15);
CmdWrite(0x02);
for(j=0;j<(value/3);j++)
{
DataWrite(bangtu[j]);
}
for(j=(value/3);j<33;j++)
{
DataWrite(0x00);
}
CmdWrite(0xb3);
CmdWrite(0x15);
CmdWrite(0x02);
for(j=33;j<33+(value/3);j++)
{
DataWrite(bangtu[j]);
}
for(j=33+(value/3);j<66;j++)
{
DataWrite(0x00);
}
CmdWrite(0xb4);
CmdWrite(0x15);
CmdWrite(0x02);
for(j=66;j<66+(value/3);j++)
{
DataWrite(bangtu[j]);
}
for(j=66+(value/3);j<99;j++)
{
DataWrite(0x00);
}
}
一周热门 更多>