⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mian.i

📁 这是从51上移植过来T6963的源码和Proteus。用CodeVisionAVR编写的。
💻 I
📖 第 1 页 / 共 2 页
字号:
0x29,0xCA,0x36,0x06,0x20,0x02,0x00,0x00}}
};

flash unsigned char  turnf[8] = {7,6,5,4,3,2,1,0};
unsigned char cData;
unsigned char gCurRow,gCurCol; 

unsigned char fnGetRow(void)
{
return(gCurRow);
}

unsigned char fnGetCol(void)
{
return(gCurCol);
}

unsigned char RD_LCM(void)
{
unsigned char temp;
DDRC=0x00;
PORTD.2  =1; 
PORTD.1=0;;  
delay_us(1);
temp=PINC;
PORTD.1=1;     
DDRC = 0xff;
return(temp);
}

void WR_DAT(unsigned char val)
{
DDRC = 0xff;
PORTD.2  =0;     
PORTC = val;
PORTD.0=0;      
delay_us(1);
delay_us(1);
PORTD.0=1;      
}

void WR_CMD(unsigned char val)
{
DDRC = 0xff;
PORTD.2  =1;    
PORTC = val;
PORTD.0=0;       
delay_us(1);
delay_us(1);
PORTD.0=1;        
}

unsigned char fnSTA01(void)
{
unsigned char i;
for(i=10;i>0;i--)
{
if((RD_LCM() & 0x03) == 0x03) 
{
break;
}
}
return(i); 
}

unsigned char fnSTA3(void)
{
unsigned char i;
for(i=10;i>0;i--)
{
if((RD_LCM() & 0x08) == 0x08)
{
break;
}
}
return(i); 
}

unsigned char fnPR1(unsigned char uCmd,unsigned char uPar1,unsigned char uPar2)
{
if(fnSTA01() == 0)
{
return 1;
}
WR_DAT(uPar1);
if(fnSTA01() == 0)
{
return 2;
}
WR_DAT(uPar2);
if(fnSTA01() == 0)
{
return 3;
}
WR_CMD(uCmd);
return(0); 
}

unsigned char write_com(unsigned char uCmd)
{
if(fnSTA01() == 0)
{
return 1;
}
WR_CMD(uCmd);
return(0); 
}

unsigned char write_data(unsigned char uData)
{
if(fnSTA3() == 0)
{
return 1;
}
WR_DAT(uData);
return(0); 
}

void fnSetPos(unsigned char urow, unsigned char ucol)
{
unsigned int iPos;
iPos = (unsigned int)urow * 30 + ucol;
fnPR1(0x24 ,iPos & 0xFF,iPos / 256);
gCurRow = urow;
gCurCol = ucol;
}

void cursor(unsigned char uRow, unsigned char uCol)
{
fnSetPos(uRow * 16, uCol);
}

void cls(void)
{
unsigned int i;
fnPR1(0x24 ,0x00,0x00); 
write_com(0xB0 ); 
for(i=0;i<240*128/8;i++) 
{
fnSTA3();
write_data(0x0); 
}
write_com(0xB2 ); 
fnPR1(0x24 ,0x00,0x00); 
gCurRow = 0; 
gCurCol = 0;
}

char LCD_ini(void)
{
if(fnPR1(0x40 ,0x00,0x00) != 0) 
{
return (0xff);
}
fnPR1(0x41 ,0x1E,0x00); 
fnPR1(0x42 ,0x00,0x00); 
fnPR1(0x43 ,0x1E,0x00); 
write_com(0xA0  | 0x01); 
write_com(0x80 ); 
write_com(0x90  | 0x08); 
return(0);
}

unsigned char write_lcd(unsigned char x,unsigned char y, flash char *ptr)
{

unsigned int c1,c2;
unsigned int i,j,uLen,uRow,uCol;
unsigned int  k;
uLen=0;
i=0;
uRow = y;
uCol = x;
fnSetPos(uRow*16,uCol);      
while (ptr[uLen]!=0) 
{
uLen++;
}
while(i<uLen)
{
c1 = ptr[i];
c2 = ptr[i+1];

uRow = fnGetRow();
uCol = fnGetCol();
if(c1 <=128)    
{
for(j=0;j<16;j++) 
{
write_com(0xB0 );                
if (c1 >= 0x20)
{
write_data(ASC_MSK[(c1-0x20)*16+j-(16-16)]);
}
else
{
write_data(cData);
}
write_com(0xB2 );              
fnSetPos(uRow+j+1,uCol);
}
if(c1 != 0x08)  	
{
uCol++;   
}

}
else    	
{
for(j=0;j<sizeof(GB_16)/sizeof(GB_16[0]);j++)  	
{
if(c1 == GB_16[j].Index[0] && c2 == GB_16[j].Index[1])
{
break;
}

}
for(k=0;k<sizeof(GB_16[0].Msk)/2;k++)
{
fnSetPos(uRow+k,uCol);
write_com(0xB0 );      		
if(j < sizeof(GB_16)/sizeof(GB_16[0]))
{
write_data(GB_16[j].Msk[k*2]);
write_data(GB_16[j].Msk[k*2+1]); 

}
else   		
{
if(k < sizeof(GB_16[0].Msk)/4)
{
write_data(0x00);
write_data(0x00);
}
else
{
write_data(0xff);
write_data(0xff);
}
}
write_com(0xB2 );
}
uCol += 2;
i++;
};
if(uCol >= 30)      					
{
uRow += 16;
if(uRow < 0x80)
{
uCol -= 30;
}
else
{
uRow = 0;
uCol = 0;
}
}
fnSetPos(uRow,uCol);
i++;
}
return uLen;        
}

void point(unsigned char x,unsigned char y,unsigned char s)
{
unsigned char x1;
x1 = x >> 3; 
fnSetPos(y,x1); 
x1 = turnf[ x & 0x07 ];
x1 = 0xF0 | x1 | s; 
write_com(x1); 
}

void Linexy(unsigned char x0,unsigned char y0,unsigned char xt,unsigned char yt,unsigned char s)
{
register unsigned char t;
int xerr = 0,yerr = 0;
int delta_x,delta_y,distance;
int incx,incy,uRow,uCol;
delta_x = xt-x0; 
delta_y = yt-y0;
uRow = x0;
uCol = y0;
if(delta_x>0)
{
incx = 1; 
}
else if( delta_x==0 )
{
incx=0; 
}
else
{
incx = -1;
delta_x = -delta_x;

}
if(delta_y>0)
{
incy=1;
}
else if( delta_y==0 )
{
incy=0; 
}
else
{
incy=-1;
delta_y=-delta_y;
}
if( delta_x > delta_y )
{
distance=delta_x; 
}
else
{
distance=delta_y;
}
for( t=0;t <= distance+1; t++ )   
{
point(uRow,uCol,s); 
xerr += delta_x;
yerr += delta_y;
if( xerr > distance )
{
xerr -= distance;
uRow += incx;
}
if( yerr > distance )
{
yerr -= distance;
uCol += incy;
}
}
}

void main(void) 
{
DDRD = 0xFF;
PORTD = 0xff;

LCD_ini();
cls();
cursor(0,0);
write_lcd(5,0,"test for:测试中文");
write_lcd(5,1,"T6963C use ATMega16");
write_lcd(5,2,"终于搞成了!!!");
write_lcd(5,3,"田建钢");
Linexy(0,0,239,0,8); 
Linexy(239,239,239,127,8); 
Linexy(0,63,239,63,8); 
Linexy(0,0,0,63,8); 
while(1)
{

}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -