首頁(yè) > 評(píng)測(cè) > 【CuriosityNano測(cè)評(píng)報(bào)告】+墨水屏的顯示驅(qū)動(dòng)
【CuriosityNano測(cè)評(píng)報(bào)告】+墨水屏的顯示驅(qū)動(dòng)
- [導(dǎo)讀]
- #申請(qǐng)?jiān)瓌?chuàng)# AVR64DD32 CuriosityNano是一款小巧的開(kāi)發(fā)板,為這款開(kāi)發(fā)板配上一款1.54寸的墨水屏是一個(gè)不錯(cuò)的選擇。目前以PIC的產(chǎn)品對(duì)墨水屏的支持并不多,為此決定將它移植到AVR64DD32開(kāi)發(fā)板。比較有意思的是,與常
#申請(qǐng)?jiān)瓌?chuàng)#
復(fù)制代碼
復(fù)制代碼復(fù)制代碼復(fù)制代碼復(fù)制代碼復(fù)制代碼復(fù)制代碼復(fù)制代碼復(fù)制代碼
復(fù)制代碼
復(fù)制代碼復(fù)制代碼復(fù)制代碼
AVR64DD32 CuriosityNano是一款小巧的開(kāi)發(fā)板,為這款開(kāi)發(fā)板配上一款1.54寸的墨水屏是一個(gè)不錯(cuò)的選擇。
目前以PIC的產(chǎn)品對(duì)墨水屏的支持并不多,為此決定將它移植到AVR64DD32開(kāi)發(fā)板。
比較有意思的是,與常規(guī)的顯示器件不同,墨水屏在寫(xiě)入顯示內(nèi)容后,在移除電源后會(huì)保持顯示的內(nèi)容,這也是為什么墨水屏被用于做電子標(biāo)簽的主要原因?芍^是省電沒(méi)商量,一旦擁有恒久流傳。圖1 顯示效果
該墨水屏共有8個(gè)引腳,它與開(kāi)發(fā)板的連接關(guān)系如下:
SCL---PD7
SDA---PD6
RST---PD3
DC ---PD2
CS ---PD1
BUSY ---PF4
在這8個(gè)引腳中,除BUSY引腳外均以輸出模式使用,而B(niǎo)USY則是以輸入模式使用,故相關(guān)的語(yǔ)句定義為:
- #define EPD_CLK_init() do { PORTD.OUTSET = PIN7_bm; PORTD.DIRSET = PIN7_bm; } while (0)
- #define EPD_MOSI_init() do { PORTD.OUTSET = PIN6_bm; PORTD.DIRSET = PIN6_bm; } while (0)
- #define EPD_RST_init() do { PORTD.OUTSET = PIN3_bm; PORTD.DIRSET = PIN3_bm; } while (0)
- #define EPD_DC_init() do { PORTD.OUTSET = PIN2_bm; PORTD.DIRSET = PIN2_bm; } while (0)
- #define EPD_CS_init() do { PORTD.OUTSET = PIN1_bm; PORTD.DIRSET = PIN1_bm; } while (0)
- #define GetValue() (VPORTF.IN & (0x1 << 4))
- #define SetPullUp() do { PORTF_PIN4CTRL |= PORT_PULLUPEN_bm; } while(0)
- #define SetDigitalInput() do { PORTF_DIRCLR = 0x10; } while(0)
由于該顯示屏的分辨率為200*200像素點(diǎn),故其幾何的參數(shù)定義為:
#define EPD_1IN54_WIDTH 200
#define EPD_1IN54_HEIGHT 200
相關(guān)引腳輸出高低電平的語(yǔ)句定義為:
- #define EPD_CLK_0 do { PORTD.OUTCLR = PIN7_bm; } while (0) //CLK
- #define EPD_CLK_1 do { PORTD.OUTSET = PIN7_bm; } while (0)
- #define EPD_MOSI_0 do { PORTD.OUTCLR = PIN6_bm; } while (0) //DIN
- #define EPD_MOSI_1 do { PORTD.OUTSET = PIN6_bm; } while (0)
- #define EPD_RST_0 do { PORTD.OUTCLR = PIN3_bm; } while (0) //RST
- #define EPD_RST_1 do { PORTD.OUTSET = PIN3_bm; } while (0)
- #define EPD_DC_0 do { PORTD.OUTCLR = PIN2_bm; } while (0) //DC
- #define EPD_DC_1 do { PORTD.OUTSET = PIN2_bm; } while (0)
- #define EPD_CS_0 do { PORTD.OUTCLR = PIN1_bm; } while (0) //C S
- #define EPD_CS_1 do { PORTD.OUTSET = PIN1_bm; } while (0)
顯示屏的復(fù)位函數(shù)為:
- void EPD_1IN54_Reset(void)
- {
- EPD_RST_1;
- DEV_Delay_ms(200);
- EPD_RST_0;
- DEV_Delay_ms(20);
- EPD_RST_1;
- DEV_Delay_ms(200);
- }
判別顯示屏是否處于忙的狀態(tài)的函數(shù)為:
- void EPD_1IN54_ReadBusy(void)
- {
- while(GetValue()==1) {
- DEV_Delay_ms(100);
- }
- }
進(jìn)入和退出墨水屏工作模式的函數(shù)為:
- int DEV_Module_Init(void)
- {
- EPD_DC_0;
- EPD_CS_0;
- EPD_RST_1;
- return 0;
- }
- void DEV_Module_Exit(void)
- {
- EPD_DC_0;
- EPD_CS_0;
- EPD_RST_0;
- }
以GPIO口模擬SPI發(fā)送發(fā)送字節(jié)數(shù)據(jù)的函數(shù)為:
- void DEV_SPI_WriteByte(unsigned char value)
- {
- u8 i;
- for(i=0; i<8;i++)
- {
- EPD_CLK_0;
- if(value & 0x80)
- EPD_MOSI_1;
- else
- EPD_MOSI_0;
- EPD_CLK_1;
- value = (value << 1);
- }
- EPD_CLK_0;
- }
向墨水屏發(fā)送指令和數(shù)據(jù)的函數(shù)為:
- void EPD_1IN54_SendCommand(u8 Reg)
- {
- EPD_DC_0;
- EPD_CS_0;
- DEV_SPI_WriteByte(Reg);
- EPD_CS_1;
- delay_us(4);
- }
- void EPD_1IN54_SendData(u8 Data)
- {
- EPD_DC_1;
- EPD_CS_0;
- DEV_SPI_WriteByte(Data);
- EPD_CS_1;
- delay_us(4);
- }
墨水屏的初始化函數(shù)為:
- void EPD_1IN54_Init(u8 Mode)
- {
- u16 i;
- EPD_1IN54_Reset();
- EPD_1IN54_SendCommand(0x01);
- EPD_1IN54_SendData((EPD_1IN54_HEIGHT - 1) & 0xFF);
- EPD_1IN54_SendData(((EPD_1IN54_HEIGHT - 1) >> 8) & 0xFF);
- EPD_1IN54_SendData(0x00);
- EPD_1IN54_SendCommand(0x0C);
- EPD_1IN54_SendData(0xD7);
- EPD_1IN54_SendData(0xD6);
- EPD_1IN54_SendData(0x9D);
- EPD_1IN54_SendCommand(0x2C);
- EPD_1IN54_SendData(0xA8);
- EPD_1IN54_SendCommand(0x3A);
- EPD_1IN54_SendData(0x1A);
- EPD_1IN54_SendCommand(0x3B);
- EPD_1IN54_SendData(0x08);
- EPD_1IN54_SendCommand(0x11);
- EPD_1IN54_SendData(0x03);
- EPD_1IN54_SendCommand(0x32);
- if(Mode == EPD_1IN54_FULL){
- for ( i = 0; i < 30; i++) {
- EPD_1IN54_SendData(EPD_1IN54_lut_full_update[i]);
- }
- }else if(Mode == EPD_1IN54_PART){
- for ( i = 0; i < 30; i++) {
- EPD_1IN54_SendData(EPD_1IN54_lut_partial_update[i]);
- }
- }else{
-
- }
- }
開(kāi)啟墨水屏顯示的函數(shù)為:
- void EPD_1IN54_TurnOnDisplay(void)
- {
- EPD_1IN54_SendCommand(0x22);
- EPD_1IN54_SendData(0xC4);
- EPD_1IN54_SendCommand(0x20);
- EPD_1IN54_SendCommand(0xFF);
- EPD_1IN54_ReadBusy();
- }
至此,前面的努力是否會(huì)奏效呢?
方法就是先去驗(yàn)證一下,如果無(wú)效,恐怕前面的工作就算交學(xué)費(fèi)。
怎么驗(yàn)證呢?
用清屏函數(shù),通常情況下清屏函數(shù)是為清除屏幕內(nèi)容服務(wù)的,這里是反其道而行之,就是讓它在屏上留下一些痕跡來(lái)判別驅(qū)動(dòng)程序是是否有效。
為此,需將清屏函數(shù)改造為一個(gè)繪制直線(xiàn)的函數(shù),其內(nèi)容如下:
- void EPD_1IN54_Clear(void)
- {
- u16 Width, Height,i,j;
- Width = (EPD_1IN54_WIDTH%8== 0)? (EPD_1IN54_WIDTH/8):(EPD_1IN54_WIDTH/8+1);
- Height = EPD_1IN54_HEIGHT;
- EPD_1IN54_SetWindow(0, 0, EPD_1IN54_WIDTH, EPD_1IN54_HEIGHT);
- for (j = 0; j < Height; j++) {
- EPD_1IN54_SetCursor(0, j);
- EPD_1IN54_SendCommand(0x24);
- for (i = 0; i < Width; i++) {
- EPD_1IN54_SendData(0XFE);
- }
- }
- EPD_1IN54_TurnOnDisplay();
- }
經(jīng)程序的編譯與下載,其運(yùn)行效果如圖2所示。這說(shuō)明驅(qū)動(dòng)是有效的,前期的工作沒(méi)白費(fèi)!
圖2 繪制直線(xiàn)
有了清屏函數(shù)的基礎(chǔ),只需將固定的清屏數(shù)據(jù)改為圖像數(shù)據(jù)就可以顯示圖片了。此外,在顯示圖像時(shí)還需選取繪圖模式,其函數(shù)為:
- void Paint_SelectImage(u8 *image)
- {
- Paint.Image = image;
- }
進(jìn)行圖像繪制的函數(shù)為:
- void Paint_DrawBitMap(const unsigned char* image_buffer)
- {
- unsigned short int x, y;
- u32 Addr = 0;
- for (y = 0; y < Paint.HeightByte; y++) {
- for (x = 0; x < Paint.WidthByte; x++) {
- Addr = x + y * Paint.WidthByte;
- Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
- }
- }
- }
在配以主程序的情況下,即可進(jìn)行顯示圖片的測(cè)試,其主程序的內(nèi)容為:
- u8 BlackImage[5000];
- int main(void) {
- EPD_CLK_init();
- EPD_MOSI_init();
- EPD_RST_init();
- EPD_DC_init();
- EPD_CS_init();
- SetDigitalInput();
- SetPullUp();
- DEV_Module_Init();
- EPD_1IN54_Init(EPD_1IN54_FULL);
- //EPD_1IN54_Clear();
- Paint_NewImage(BlackImage, EPD_1IN54_WIDTH, EPD_1IN54_HEIGHT, 270, WHITE);
- Paint_SelectImage(BlackImage);
- Paint_DrawBitMap(gImage_1in54);
- EPD_1IN54_Display(BlackImage);
- DEV_Delay_ms(2000);
- EPD_1IN54_Sleep();
- DEV_Delay_ms(2000);
- while(1);
- }
經(jīng)編譯下載,其測(cè)試效果就是圖1的顯示內(nèi)容,證明繪圖函數(shù)也成功了!
在添加圖形繪制函數(shù)的情況下,可繪制點(diǎn)、直線(xiàn)、矩形及圓等并可以進(jìn)行填充處理。此外,在配置字庫(kù)的條件下,可實(shí)現(xiàn)字符和中文的顯示,其實(shí)現(xiàn)的效果如圖3和圖4所示。
圖3 繪制圖形
圖4 顯示字符及數(shù)值
實(shí)現(xiàn)顯示效果的主程序?yàn)椋?/div>復(fù)制代碼
- int main(void) {
- EPD_CLK_init();
- EPD_MOSI_init();
- EPD_RST_init();
- EPD_DC_init();
- EPD_CS_init();
- SetDigitalInput();
- SetPullUp();
- DEV_Module_Init();
- EPD_1IN54_Init(EPD_1IN54_FULL);
- Paint_NewImage(BlackImage, EPD_1IN54_WIDTH, EPD_1IN54_HEIGHT, 270, WHITE);
- Paint_SelectImage(BlackImage);
- Paint_DrawBitMap(gImage_1in54);
- Paint_Clear(WHITE);
- Paint_DrawPoint(5, 10, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
- Paint_DrawPoint(5, 25, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
- Paint_DrawPoint(5, 40, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
- Paint_DrawPoint(5, 55, WHITE, DOT_PIXEL_4X4, DOT_STYLE_DFT);
-
- Paint_DrawLine(20, 10, 70, 60, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
- Paint_DrawLine(70, 10, 20, 60, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
- Paint_DrawLine(170, 15, 170, 55, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
- Paint_DrawLine(150, 35, 190, 35, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
-
- Paint_DrawRectangle(20, 10, 70, 60, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
- Paint_DrawRectangle(85, 10, 130, 60, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
- Paint_DrawCircle(170, 35, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
- Paint_DrawCircle(170, 85, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
-
- EPD_1IN54_Display(BlackImage);
- DEV_Delay_ms(2000);
- EPD_1IN54_Sleep();
- DEV_Delay_ms(2000);
- while(1);
- }
這樣在PIC的產(chǎn)品上,墨水屏也可以煥發(fā)出光彩了!
- 本文系21ic原創(chuàng),未經(jīng)許可禁止轉(zhuǎn)載!
網(wǎng)友評(píng)論
- 聯(lián)系人:巧克力娃娃
- 郵箱:board@21ic.com
- 我要投稿
-
歡迎入駐,開(kāi)放投稿
行業(yè)新聞
熱門(mén)標(biāo)簽
論壇活動(dòng)
more+
公開(kāi)課
more+
項(xiàng)目外包
more+
- NRF52810藍(lán)牙數(shù)字耳機(jī)找人定制
預(yù)算:¥30005天前
- 125KW模塊式PCS軟硬件外包開(kāi)發(fā)
預(yù)算:¥1100000015小時(shí)前
- 12V汽車(chē)啟動(dòng)電源項(xiàng)目BMS設(shè)計(jì)
預(yù)算:¥50000023小時(shí)前
- 數(shù)據(jù)可視化軟件 開(kāi)發(fā)
預(yù)算:¥5000023小時(shí)前
- PLC項(xiàng)目調(diào)試修改
預(yù)算:¥100001天前
- 起動(dòng)電機(jī)控制器開(kāi)發(fā)
預(yù)算:¥1100001天前