找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2450|回复: 0
打印 上一主题 下一主题
收起左侧

MikroC写的ATmega16驱动spi接口128x64屏例子带仿真

[复制链接]
跳转到指定楼层
楼主
MikroC写的ATmega16驱动spi接口128x64屏例子带仿真。自带驱动库,图片转换成数组的工具也集成在软件内,可到官网下载无须注册。


单片机源程序如下:
  1. const code char truck_bmp[1024];
  2. const code char B_bmp[1024];
  3. // Port Expander module connections
  4. sbit  SPExpanderRST at PORTB0_bit;
  5. sbit  SPExpanderCS  at PORTB1_bit;
  6. sbit  SPExpanderRST_Direction at DDB0_bit;
  7. sbit  SPExpanderCS_Direction  at DDB1_bit;
  8. // End Port Expander module connections

  9. void Delay2s(){                         // 2 seconds delay function
  10.   Delay_ms(2000);
  11. }

  12. void main() {
  13.   char counter;
  14.   char *someText;
  15.   // If Port Expander Library uses SPI1 module
  16.   SPI1_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV2, _SPI_CLK_HI_TRAILING);  // Initialize SPI module used with PortExpander

  17.   // // If Port Expander Library uses SPI2 module
  18.   //  SPI2_Init_Advanced(_SPI_MASTER, _SPI_FCY_DIV2, _SPI_CLK_HI_TRAILING);  // Initialize SPI module used with PortExpander

  19.   SPI_Glcd_Init(0);                              // Initialize Glcd via SPI
  20.   SPI_Glcd_Fill(0x00);                           // Clear Glcd

  21.   while(1) {
  22.     SPI_Glcd_Image(truck_bmp);                   // Draw image
  23.     Delay2s(); Delay2s();
  24.     SPI_Glcd_fill(0x00);                                  // Clear GLCD
  25.     //SPI_Glcd_PartialImage(0,0,68,30,128,64,truck_bmp);    // Partial image
  26.     //Delay_ms(500);
  27.     //SPI_Glcd_PartialImage(24,16,68,30,128,64,truck_bmp);
  28.     //Delay_ms(500);
  29.     //SPI_Glcd_PartialImage(56,34,68,30,128,64,truck_bmp);
  30.     //Delay2s(); Delay2s();
  31.     //SPI_Glcd_Fill(0x00);                             // Clear GLCD
  32.    
  33.     SPI_Glcd_Box(62,40,124,56,1);                    // Draw box
  34.     SPI_Glcd_Rectangle(5,5,84,35,1);                 // Draw rectangle
  35.     Delay_ms(1000);
  36.     SPI_Glcd_Rectangle_Round_Edges(2,2,87,38,7,1);
  37.     Delay_ms(1000);
  38.     SPI_Glcd_Rectangle_Round_Edges_Fill(8,8,81,32,12,1);
  39.     Delay_ms(1000);
  40.     SPI_Glcd_Line(0, 0, 127, 63, 1);                 // Draw line
  41.     Delay2s();

  42.     SPI_Glcd_Image(B_bmp);
  43.     Delay2s();
  44.    
  45.     for(counter = 5; counter < 60; counter+=5 ) {  // Draw horizontal and vertical lines
  46.       Delay_ms(250);
  47.       SPI_Glcd_V_Line(2, 54, counter, 1);
  48.       SPI_Glcd_H_Line(2, 120, counter, 1);
  49.       }
  50.     Delay2s();

  51.     SPI_Glcd_Fill(0x00);                         // Clear Glcd
  52.     SPI_Glcd_Set_Font(Character8x7, 8, 7, 32);   // Choose font, see __Lib_GLCDFonts.c in Uses folder
  53.     SPI_Glcd_Write_Text("mikroE", 5, 7, 2);      // Write string

  54.     for (counter = 1; counter <= 10; counter++)  // Draw circles
  55.       SPI_Glcd_Circle(63,32, 3*counter, 1);
  56.     Delay2s();

  57.     SPI_Glcd_Circle_Fill(63,32, 30, 1);          // Draw circles
  58.     Delay2S();

  59.     SPI_Glcd_Box(12,20, 70,63, 2);               // Draw box
  60.     Delay2s();

  61.     SPI_Glcd_Fill(0xFF);                         // Fill Glcd

  62.     SPI_Glcd_Set_Font(Character8x7, 8, 7, 32);   // Change font
  63.     someText = "8x7 Font";
  64.     SPI_Glcd_Write_Text(someText, 5, 0, 2);      // Write string
  65.     Delay2s();

  66.     SPI_Glcd_Set_Font(System3x5, 3, 5, 32);      // Change font
  67.     someText = "3X5 CAPITALS ONLY";
  68.     SPI_Glcd_Write_Text(someText, 60, 2, 2);     // Write string
  69.     Delay2s();

  70.     SPI_Glcd_Set_Font(font5x7, 5, 7, 32);        // Change font
  71.     someText = "5x7 Font";
  72.     SPI_Glcd_Write_Text(someText, 5, 4, 2);      // Write string
  73.     Delay2s();

  74.     SPI_Glcd_Set_Font(FontSystem5x7_v2, 5, 7, 32); // Change font
  75.     someText = "5x7 Font (v2)";
  76.     SPI_Glcd_Write_Text(someText, 5, 6, 2);        // Write string
  77.     Delay2s();
  78.     }
  79. }
复制代码

所有资料51hei提供下载:
ATMEGA16 SPI128x64.zip (29.35 KB, 下载次数: 15)

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表