åèï¼ks1208+12864lcdå±å¹æ§å¶çµæºï¼#include<avr/io.h>
#include<avr/delay.h>
#include<string.h>
#define INT8U unsigned char#define lcd_starthang 0b11000000 // èµ·å§è¡
#define lcd_ye 0XB8 // 页æ令
#define lcd_lie 0X40 // åæ令
#define RW PD0
#define DI PD1
#define E PD2
#define CS1 PD3
#define CS2 PD4
#define RST PD5#define lcd_port PORTC //液æ¶æ线
#define lcd_ctrl PORTD //æ§å¶ç«¯å£
#define lcd_ddr DDRC //è¾å
¥è¾åº
#define lcd_pin PINC //æ§å¶ç¶æçæ°æ®
#define RW1() lcd_ctrl |=_BV(RW);
#define RW0() lcd_ctrl &=~_BV(RW);//æ°æ®æ»çº¿#define DI1() lcd_ctrl |=_BV(DI);
#define DI0() lcd_ctrl &=~_BV(DI);#define CS11() lcd_ctrl |=_BV(CS1);
#define CS10() lcd_ctrl &=~_BV(CS1);//çéä¿¡å·
#define CS21() lcd_ctrl |=_BV(CS2);
#define CS20() lcd_ctrl &=~_BV(CS2);#define E1() lcd_ctrl |=_BV(E);
#define E0() lcd_ctrl &=~_BV(E);//使è½#define RST1() lcd_ctrl |=_BV(RST);
#define RST0() lcd_ctrl &=~_BV(RST);/å¤ä½char fxshow=0;
void wait_lcd_ready()
{ check_busy:
lcd_ddr =0X00;
lcd_port=0Xff;
RW1();asm ("nop"); DI0();
E1(); asm ("nop"); E0();
if (lcd_pin & 0x80) goto check_busy;
}
//lcdæ§å¶æ令å½æ°
void write_lcd_command(INT8U ABC)
{wait_lcd_ready();<br> lcd_ddr =0XFF; <br> lcd_port=0XFF;<br> RW0();asm ("nop");DI0();<br> lcd_port=ABC;<br> E1();asm ("nop");E0();<br>} void writedata(INT8U dat)
{ wait_lcd_ready();
lcd_ddr =0XFF;
lcd_port=0XFF;
RW0();asm ("nop");DI1();
if(!fxshow) lcd_port=dat;else lcd_port=~dat;
E1();asm ("nop");E0();
}
//-----------------------------------------------------åå§å
void lcd_chushihua(){ write_lcd_command(0x3f);_delay_ms(15);}//void lcd_show(INT8U y,INT8U l,INT8U j,INT8U *r)//å 页 y ãå å lãå 个å符 jã
{INT8U i;<br> if(l<64)<br> {CS11();CS20(); <br> write_lcd_command(lcd_ye+y);<br> write_lcd_command(lcd_lie+l);</p><p> if(l+j<64)<br> {<br> for (i=0;i<j;i++) writedata(r[i]);<br> }
else
{for (i=0;i<64-l;i++)writedata(r[i]);//zuoåç¶æ¾ç¤º<br> CS10();CS21();<br> write_lcd_command(lcd_ye+y);<br> write_lcd_command(lcd_lie);<br> for (i=64-l;i<j;i++) writedata(r[i]);//æåç¶æ¾ç¤º<br> <br> }
}
else{ CS10();CS21();
write_lcd_command(lcd_ye+y);
write_lcd_command(lcd_lie+l-64);
for (i=0;i<j;i++) writedata(r[i]);
}
}
void qingping()
{ INT8U i,j;
CS11();CS21();
write_lcd_command(lcd_ye);
write_lcd_command(lcd_lie);
for (i=0;i<8;i++)
{ write_lcd_command(lcd_ye+i);
for(j=0;j<128;j++)
{write_lcd_command(lcd_lie+j);<br> writedata(0x00);}
}
}
//-----------------------------8*16void display816(INT8U y,INT8U l,INT8U *r){ lcd_show(y, l,8, r );//å 页 y ãå å lãå 个å符 jã
lcd_show(y+1,l,8,r+8 );} //--------------------------------ä¸ä¸²8*16void display8161(INT8U y,INT8U l,INT8U D,INT8U *r){INT8U i;<br> for(i=0;i<D;i++)<br> { display816(y,l+i*8,r+16*i);}}//------------------------------8*16void display1616(INT8U y,INT8U l,INT8U *r){ lcd_show(y, l,16, r );//å 页 y ãå å lãå 个å符 jã
lcd_show(y+1,l,16,r+16);
}void display16161(INT8U y,INT8U l,INT8U D,INT8U *r){INT8U i;<br> for(i=0;i<D;i++)<br> { display1616(y,l+i*16,r+32*i);}
}
//----------------------------------------------------
void guang(INT8U i,INT8U j)
{
CS11();CS21();
write_lcd_command(lcd_ye);
write_lcd_command(lcd_lie);
write_lcd_command(i);
write_lcd_command(j);
writedata(0x00);
}//------------------------------------------------
//---------------------------------------------------
//----------------------------------------------------
#include<avr/io.h>
#include<avr/delay.h>
#include<string.h>
#include<avr/interrupt.h>
#define INT8U unsigned char
#define INT16U unsigned int
//-------------------------------------æé®å®ä¹
#define k1() ((PINA & (1<<PA0))==0x00)
#define k2() ((PINA & (1<<PA1))==0x00)
#define k3() ((PINA & (1<<PA2))==0x00)
#define k4() ((PINA & (1<<PA3))==0x00)
#define k5() ((PINA & (1<<PA4))==0x00)
#define k6() ((PINA & (1<<PA5))==0x00)
#define k7() ((PINA & (1<<PA6))==0x00)
#define k8() ((PINA & (1<<PA7))==0x00)
//-----------------------------------------------------
#define RST PB2
#define SLCK PB1
#define IO PB0 #define DDR_ DDRB
#define PORT_ PORTB
#define io() (PINB & (1<<IO))
#define DDR_1() DDR_|=(1<<IO)
#define DDR_0() DDR_&= ~(1<<IO)
#define SLCK1() PORT_ |=(1<<SLCK)
#define SLCK0() PORT_ &=~(1<<SLCK)#define IO1() PORT_ |=(1<<IO)
#define IO0() PORT_ &=~(1<<IO)
#define RST1() PORT_ |=(1<<RST)
#define RST0() PORT_ &=~(1<<RST)
INT8U time[];//----------------------------------------------------------------------
//-------------------------------------------------------------------
//-------------------------------------------------------------------
const INT8U timeword[]=
};
const INT8U number[]={
/};
const INT8U number1[]={
//--------------------------åå
¥dat
void write(char dat)
{ DDR_1();
char i;
for (i=0;i<8;i++)
{
if(dat & 0x01) IO1();else IO0() ;
dat=dat>>1;
SLCK0();
SLCK1();
}
}
//--------------------------------------------------------
//----------------------------è¾åºdat
char read11()
{ char dat=0x00;
DDR_0();
char i;
for (i=0;i<8;i++)
{SLCK1(); <br> SLCK0();<br> if(io()) dat |=(1<<i);<br> }
return dat/16*10+dat%16;//--------转æ¢ä¸ºåè¿å¶
}//--------------------------------------------读åæå®å°åadressä¸çdat--------
char readadress(INT8U adress)
{ INT8U dat;
RST1();
write(adress);
dat=read11();
RST0();
return dat;
}
//-----------------------------------------------------------
//------------------------------------------å¨æå®å°åadressåå
¥dat-----------
void wadress(char adress ,char dat)
{ RST1();
write(adress) ;
write(dat);
RST0();
}//------------------------------------------------读åæ¶é´
//-------------------------------------------------
void readtime()
{
INT8U i ,adress=0x81;
for (i=0;i<7;i++)
{
time[i]=readadress(adress);
adress += 2;}
}
//------------------------------------------------设置æ¶é´
//-----------------------------------------------------
void set()
{
INT8U i;
wadress(0x8E ,0x00);
for (i=0;i<3;i++)
{
wadress(0X80+2*i ,(time[i]/10<<4 )| (time[i]%10));
} wadress(0x8E ,0x80);
}
//--------------------------------------------åç¸æ¥è¿å
«ææ¹å¼
//-------------æ£è½¬å±ç£åºå为A->AB->B->BC->C->CD->D->DA
const INT8U zheng[]={0x01,0x03,0x02,0x06,0x04,0x0C,0x08,0x09};//------------------å转å±ç£åºå为A->AD->D->CD->C->BC->B->AB
//--------------------------------------
const INT8U fan[]={0x01,0x09,0x08,0x0C,0x04,0x06,0x02,0x03};
//-----------------------------------------------------------------
// æ¥è¿çµæºæ£è½¬æå转nå
//-----------------------------------------------------------------
void STEP_MOTOR_RUN(INT8U Direction,INT8U n)
{
INT8U i,j;
for (i=0;i<n;i++)
{
for(j=0;j<8;j++)
{
if(k3()) return;
if(Direction==0) PORTB=zheng[j];
if(Direction==1) PORTB= fan[j];
_delay_ms(200);
}
PORTB=0x01;
}
}
//--------------------------------------------
extern void lcd_chushihua(); //å®ä¹å¨å«çæ件ä¸
extern void qingping();
extern void display16161(INT8U y,INT8U l,INT8U C,INT8U *m);
extern void display8161(INT8U y,INT8U l,INT8U D,INT8U *r);
extern void display1616(INT8U y,INT8U l,INT8U *r);
extern void display816(INT8U y,INT8U l,INT8U *r);
//-----------------------------------------------------------------------void reshtime()
{ INT8U s,h,m,d,m1,w,y;
s=time[0]; m=time[1]; h=time[2];d=time[3];m1=time[4];w=time[5];y=time[6];
display816(1,1,(INT8U*) (number+h/10*16)); //------æ¶
display816(1,9,(INT8U*) (number+h%10*16)); //
display816(1,17,(INT8U*) (number+m/10*16)); //------å
display816(1,25,(INT8U*) (number+m%10*16)); //
display816(1,33,(INT8U*) (number+s/10*16)); //------ç§
display816(1,41,(INT8U*) (number+s%10*16)); //
display816(3,17,(INT8U*) (number+d/10*16)); //------æ¥
display816(3,25,(INT8U*) (number+d%10*16)); //
display816(3,1,(INT8U*) (number+m1/10*16)); //------æ
display816(3,9,(INT8U*) (number+m1%10*16)); //
display816(3,33,(INT8U*) (number+y/10*16)); //------å¹´
display816(3,41,(INT8U*) (number+y%10*16)); //
display816(3,49,(INT8U*) (number+2*16)); //------20
display816(3,57,(INT8U*) (number)); //------20
display816(5,1,(INT8U*) (number+w*16)); //------å¨
}int main(){INT8U r=5,i=0,j=0,k=0;</p><p><br> DDRA=0X00;PORTA=0XFF;<br> DDRB=0XFF;<br> DDRD=0XFF;PORTD=0XFF; <br> TCCR0=0x05;<br> TCNT0=256-1000000/1024*0.05;<br> <br> TIMSK =0x01;<br> sei();<br> //--------------------------------------------------------------<br> //----------------------------------åºå®å¹´ãæãæ¥ãæ¶ãåãç§ã<br> //-----------------------------------------------------------------------<br> display1616(1,26,(INT8U*) timeword); //å 页 y ãå å lãå 个å符 jã<br> display1616(1,58,(INT8U*) (timeword+32));<br> display1616(1,90,(INT8U*) (timeword+64));<br> display1616(4,26,(INT8U*) (timeword+96)); //å 页 y ãå å lãå 个å符 jã<br> display1616(4,58,(INT8U*) (timeword+128));<br> display1616(4,90,(INT8U*) (timeword+160));<br> while(1)<br> { readtime();<br> <br> if(k1())<br> { <br> <br> while(k1());<br> j=(j+1)%7;<br> display816(1+i*3,42+j*8,(INT8U*) number1);<br> // while(k1());STEP_MOTOR_RUN(0,r);//STEP_MOTOR_RUN(INT8U Direction,INT8U n)<br> <br> }
if(k2())
{while(k2());<br> display816((1+i*3),(26+j*32),(INT8U*) (number+k*16));<br> k=(k+1)%10;<br> //;STEP_MOTOR_RUN(1,r);<br> } if (k3())
{
display816((1+i*3),(26+j*32),(INT8U*) (number+k*16));
j=(j+1)%10;
}
}} ISR(TIMER0_OVF_vect) {
TCNT0=256-1000000/1024*0.05;
reshtime();
}
温馨提示:内容为网友见解,仅供参考