查看:2771|回复:0
MikroC写的ATmega16驱动spi接口128x64屏例子带仿真。自带驱动库,图片转换成数组的工具也集成在软件内,可到官网下载无须注册。
单片机源程序如下:
复制代码
所有资料51hei提供下载:
ATMEGA16 SPI128x64.zip(29.35 KB, 下载次数: 15)
单片机源程序如下:
- const code char truck_bmp[1024];
- const code char B_bmp[1024];
- // Port Expander module connections
- sbit SPExpanderRST at PORTB0_bit;
- sbit SPExpanderCS at PORTB1_bit;
- sbit SPExpanderRST_Direction at DDB0_bit;
- sbit SPExpanderCS_Direction at DDB1_bit;
- // End Port Expander module connections
- void Delay2s(){ // 2 seconds delay function
- Delay_ms(2000);
- }
- void main() {
- char counter;
- char *someText;
- // If Port Expander Library uses SPI1 module
-
SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV2, _SPI_CLK_HI_TRAILING); // Initialize SPI module used with PortExpander
- // // If Port Expander Library uses SPI2 module
-
// SPI2_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV2, _SPI_CLK_HI_TRAILING); // Initialize SPI module used with PortExpander
- SPI_Glcd_Init(0); // Initialize Glcd via SPI
- SPI_Glcd_Fill(0x00); // Clear Glcd
- while(1) {
-
SPI_Glcd_Image(truck_bmp); // Draw image
- Delay2s(); Delay2s();
- SPI_Glcd_fill(0x00); // Clear GLCD
-
//SPI_Glcd_PartialImage(0,0,68,30,128,64,truck_bmp); // Partial image
- //Delay_ms(500);
-
//SPI_Glcd_PartialImage(24,16,68,30,128,64,truck_bmp);
- //Delay_ms(500);
-
//SPI_Glcd_PartialImage(56,34,68,30,128,64,truck_bmp);
- //Delay2s(); Delay2s();
- //SPI_Glcd_Fill(0x00); // Clear GLCD
-
-
SPI_Glcd_Box(62,40,124,56,1); // Draw box
-
SPI_Glcd_Rectangle(5,5,84,35,1); // Draw rectangle
- Delay_ms(1000);
-
SPI_Glcd_Rectangle_Round_Edges(2,2,87,38,7,1);
- Delay_ms(1000);
-
SPI_Glcd_Rectangle_Round_Edges_Fill(8,8,81,32,12,1);
- Delay_ms(1000);
- SPI_Glcd_Line(0, 0, 127, 63, 1); // Draw line
- Delay2s();
- SPI_Glcd_Image(B_bmp);
- Delay2s();
-
- for(counter = 5; counter< 60; counter+=5 ) { // Draw horizontal and vertical lines
- Delay_ms(250);
- SPI_Glcd_V_Line(2, 54, counter, 1);
- SPI_Glcd_H_Line(2, 120, counter, 1);
- }
- Delay2s();
- SPI_Glcd_Fill(0x00); // Clear Glcd
-
SPI_Glcd_Set_Font(Character8x7, 8, 7, 32); // Choose font, see __Lib_GLCDFonts.c in Uses folder
-
SPI_Glcd_Write_Text("mikroE", 5, 7, 2); // Write string
- for (counter = 1; counter< = 10; counter++) // Draw circles
- SPI_Glcd_Circle(63,32, 3*counter, 1);
- Delay2s();
-
SPI_Glcd_Circle_Fill(63,32, 30, 1); // Draw circles
- Delay2S();
- SPI_Glcd_Box(12,20, 70,63, 2); // Draw box
- Delay2s();
- SPI_Glcd_Fill(0xFF); // Fill Glcd
-
SPI_Glcd_Set_Font(Character8x7, 8, 7, 32); // Change font
- someText = "8x7 Font";
-
SPI_Glcd_Write_Text(someText, 5, 0, 2); // Write string
- Delay2s();
-
SPI_Glcd_Set_Font(System3x5, 3, 5, 32); // Change font
- someText = "3X5 CAPITALS ONLY";
-
SPI_Glcd_Write_Text(someText, 60, 2, 2); // Write string
- Delay2s();
-
SPI_Glcd_Set_Font(font5x7, 5, 7, 32); // Change font
- someText = "5x7 Font";
-
SPI_Glcd_Write_Text(someText, 5, 4, 2); // Write string
- Delay2s();
-
SPI_Glcd_Set_Font(FontSystem5x7_v2, 5, 7, 32); // Change font
- someText = "5x7 Font (v2)";
-
SPI_Glcd_Write_Text(someText, 5, 6, 2); // Write string
- Delay2s();
- }
- }
所有资料51hei提供下载:
ATMEGA16 SPI128x64.zip(29.35 KB, 下载次数: 15)