新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PIC16F917 NOKIA5110 LCD 任意畫(huà)點(diǎn)程序

PIC16F917 NOKIA5110 LCD 任意畫(huà)點(diǎn)程序

作者: 時(shí)間:2016-11-18 來(lái)源:網(wǎng)絡(luò) 收藏

本文引用地址:http://m.butianyuan.cn/article/201611/316058.htm

void LCD_Print_Pix(unsigned char x,unsigned char y,unsigned char display_mode);//1/4區(qū)域任意畫(huà)點(diǎn)程序

unsigned char bank1 Lcd_Buffer0[3][21] = {{0}, {0}}; //LCD顯示數(shù)據(jù)緩存區(qū)
unsigned char bank2 Lcd_Buffer1[3][21] = {{0}, {0}}; //LCD顯示數(shù)據(jù)緩存區(qū)
///////////////////////LCD任意位置寫(xiě)點(diǎn)/////////////
//必須把LCD顯示數(shù)據(jù)緩存,這樣才可以任意畫(huà)點(diǎn),RAM需要(48/6)×84個(gè)字節(jié)才能整個(gè)屏幕寫(xiě)
//本程序是1/4 LCD區(qū)域內(nèi)顯示任意點(diǎn)
//x=x軸坐標(biāo),y=y軸坐標(biāo),display_mode=0不顯示;display_mode=1顯示點(diǎn);
void LCD_Print_Pix(unsigned char x,unsigned char y,unsigned char display_mode)
{
unsigned char row;
unsigned char offset;
unsigned char lcd_data;
unsigned char i;

if ( x > 41 ) return; //由于RAM空間問(wèn)題,對(duì)1/4屏幕操作
if ( y > 23 ) return;
if ( display_mode > 1 ) return;

row = y / 8;
offset = y % 8;

if(x<=20)lcd_data = Lcd_Buffer0[row][x]; //從緩沖區(qū)讀LCD顯示數(shù)據(jù)
if(x>20)lcd_data = Lcd_Buffer1[row][x-21];


if (display_mode == 0)
{
lcd_data &= (~(0x01 << offset));//擦除
}
else if (display_mode== 1)
{
lcd_data|= (0x01 << offset);//畫(huà)點(diǎn)
}

if(x<=20)Lcd_Buffer0[row][x] = lcd_data; //LCD顯示數(shù)據(jù)保存到緩沖區(qū)
if(x>20) Lcd_Buffer1[row][x-21] = lcd_data;

lcd_data=change_char_h_l(lcd_data);//y軸顯示時(shí)高低位互換


LCD_set_XY(x,row);
////寫(xiě)LCD數(shù)據(jù)///
LCD_CE=0 ; // 使能LCD
LCD_DC=1 ; // 傳送數(shù)據(jù)
for(i=0;i<8;i++)
{
if((lcd_data>>i)&0x01)
{SPI_MOSI=1;}
else
{SPI_MOSI=0;}
SPI_CLK=0;
NOP();
SPI_CLK=1;
}
LCD_CE=1 ;// 關(guān)閉LCD
/////////
}

例子:

LCD_Print_Pix(0,0,1); x顯示一個(gè)點(diǎn)

畫(huà)個(gè)方塊:

for(i=0;i<15;i++)
{
LCD_Print_Pix(i,0,1);
LCD_Print_Pix(i,9,1);
}
for(i=0;i<10;i++)
{
LCD_Print_Pix(0,i,1);
LCD_Print_Pix(14,i,1);
}



評(píng)論


技術(shù)專區(qū)

關(guān)閉