久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5383|回復: 6
收起左側

AVR萬年電子日歷C程序

[復制鏈接]
ID:82781 發表于 2015-6-13 23:23 | 顯示全部樓層 |閱讀模式
main.c如下:
  1. #include "iom16v.h"
  2. #include "ds1302.h"
  3. #include "macros.h"
  4. #include "lcd12864.h"
  5. #define xtal  1
  6. uchar  disp_time[33]="2008年11月27日  21:49:00  星期日";
  7. uchar week[14] = "一二三四五六天";
  8. /*----------鍵盤相關聲明-------------------------------------*/
  9. #define key (PINA  & BIT(0))     //功能鍵
  10. #define key1 (PINA  & BIT(1))     //只有加1鍵
  11. uchar sum,keyflag=0;   //調用時,分,秒,標志,調用鍵盤處理標志.

  12. /*延時函數*/
  13. void delay_ms(unsigned char i) {
  14. unsigned char a, b;
  15. for (a = 1; a < i; a++) {
  16.   for (b = 1; b; b++) {
  17.    ;
  18.    }
  19.   }
  20. }


  21. /*********時間寫屏刷新函數***********/   
  22. void  disp_reset(void)   
  23. {  

  24.   // disp_time[0] = time_buf[0]/10+48; //年
  25.   // disp_time[1] = time_buf[0]%10+48;
  26.    disp_time[2] =  time_buf[1] /10+48;//年
  27.    disp_time[3] =  time_buf[1] %10+48;
  28.    disp_time[6] =  time_buf[2] /10+48;//月
  29.    disp_time[7] =  time_buf[2] %10+48;
  30.    disp_time[10] =  time_buf[3] /10+48;//日
  31.    disp_time[11] =  time_buf[3] %10+48;
  32.    disp_time[16] =  time_buf[4] /10+48;//時
  33.    disp_time[17] =  time_buf[4] %10+48;
  34.    disp_time[19] = time_buf[5]/10+48;//分
  35.    disp_time[20] = time_buf[5]%10+48;
  36.    disp_time[22] = time_buf[6]/10+48;//秒
  37.    disp_time[23] = time_buf[6]%10+48;
  38.    disp_time[30] = time_buf[7]/10+48;//周
  39.    disp_time[31] = time_buf[7]%10+48;
  40.    
  41.    switch (time_buf[7]%16)
  42.    {
  43.      case 0:
  44.        //LCD_PutStr(2,4,"日");
  45.     disp_time[30] =week[0];
  46.     disp_time[31] =week[1];
  47.     break;
  48.      case 1:
  49.        //LCD_PutStr(2,4,"一");
  50.     disp_time[30] =week[2];
  51.     disp_time[31] =week[3];
  52.     break;
  53.   case 2:
  54.        //LCD_PutStr(2,4,"二");
  55.     disp_time[30] =week[4];
  56.     disp_time[31] =week[5];
  57.     break;
  58.      case 3:
  59.        disp_time[30] =week[6];
  60.     disp_time[31] =week[7];
  61.     break;
  62.   case 4:
  63.        disp_time[30] =week[8];
  64.     disp_time[31] =week[9];
  65.     break;  
  66.   case 5:
  67.        disp_time[30] =week[10];
  68.     disp_time[31] =week[11];
  69.     break;  
  70.   case 6:
  71.        disp_time[30] =week[12];
  72.     disp_time[31] =week[13];
  73.     break;
  74.   default:
  75.        break;
  76.    }
  77.       
  78.    LCD_PutStr(0,0,"當前日期是:");
  79.    LCD_PutStr(1,0,disp_time);
  80. }
  81. /*---------------按鍵處理相關函數--------------------------*/
  82. /************************************************************
  83. 函數名稱:void scanner()
  84. 功能描述: 按鍵函數
  85. *************************************************************/
  86. void scanner()
  87. { uchar i,j;  
  88. if(!key)     //功能鍵按下
  89. { delay_ms(500);    //延時500MS
  90.    if(!key)    //還按下,退出時間調整
  91.    { keyflag=0;   //標志位為0
  92.     sum=0;    //清0
  93.      LCD_WriteCmd(0x0C);//清閃爍
  94.   LCD_PutStr(3,0,"           ");
  95.   
  96.     for(i=0;i<7;i++) //十進制轉十六進制
  97.     { j=time_buf[ i]/10;
  98.          time_buf=time_buf%10;
  99.          time_buf=time_buf+16*j;
  100.     }
  101.         ds1302_init();//DS1302初始化
  102.         delay_ms(10);
  103.     ds1302_write_time();//寫入1302
  104.    
  105.     while(!key); //等待釋放
  106.     delay_ms(10);   //延時消抖
  107.    }
  108.    else     //500MS內放開
  109.    { keyflag=1;   //標志為1,進行時間調整
  110.     sum++;    //功能鍵加1
  111. switch (sum)
  112.         {
  113.      case 1:
  114.         LCD_PutStr(3,0,"請調整年份");
  115.      break;
  116.      case 2:
  117.         LCD_PutStr(3,0,"請調整月份");
  118.      break;
  119.   case 3:
  120.         LCD_PutStr(3,0,"請調整日期");
  121.      break;
  122.      case 4:
  123.         LCD_PutStr(3,0,"請調整時鐘");
  124.      break;
  125.      case 5:
  126.         LCD_PutStr(3,0,"請調整分鐘");
  127.      break;
  128.      case 6:
  129.         LCD_PutStr(3,0,"請調整秒鐘");
  130.      break;
  131.   case 7:
  132.         LCD_PutStr(3,0,"請調整星期");
  133.      break;
  134.      default:
  135.         break;
  136.     }
  137.    
  138.     if(sum==8)  
  139.      sum=0;
  140.     switch(sum)
  141.      {
  142.   case 1:   //  年閃爍   
  143.          LCD_WriteCmd(0x90+1);
  144.          LCD_WriteCmd(0x0f);
  145.          break;
  146.      case 2:   //為2,月閃爍
  147.       // write_single(3,2,"-?");
  148.       LCD_WriteCmd(0x90+3);
  149.          break;
  150.      case 3:   //日閃爍
  151.          LCD_WriteCmd(0x90+5);
  152.          break;
  153.   case 4:   //時閃爍
  154.          LCD_WriteCmd(0x88+0);
  155.          break;
  156.      case 5:   //分閃爍
  157.          //LCD_WriteCmd(0x88+4);
  158.      write_single(3,2,"0");
  159.      LCD_WriteCmd(0x06);        //寫入時,游標右移動
  160.    
  161.          break;
  162.      case 6:   //秒閃爍
  163.          LCD_WriteCmd(0x88+3);
  164.          break;
  165.      case 7:   //星期閃爍
  166.          LCD_WriteCmd(0x88+7);
  167.          break;
  168.     }
  169.    }
  170. }
  171. if(sum)      //功能鍵按下
  172. {      
  173.    if(!key1)
  174.    { delay_ms(10);
  175.     if(!key1)
  176.     { while(!key1);//等待加1鍵釋放
  177.      delay_ms(10);
  178.      if(sum==1) //年
  179.      {  time_buf[1]++;
  180.       if(   time_buf[1]  ==100)
  181.        time_buf[1]=0;
  182.       disp_reset();
  183.      }
  184.      if(sum==2)  //月
  185.      {  
  186.    time_buf[2]++;
  187.       if( time_buf[2] ==13)
  188.        time_buf[2]=1;
  189.        disp_reset();
  190.      }
  191.      if(sum==3)//日
  192.      { time_buf[3]++;
  193.       if(  time_buf[3]  ==32)
  194.        time_buf[3]=1;
  195.       disp_reset();
  196.      }
  197.      if(sum==4)//時
  198.      {
  199.        time_buf[4]++;
  200.       if( time_buf[4] ==24)
  201.        time_buf[4]=0;
  202.       disp_reset();
  203.      }
  204.      if(sum==5)//分
  205.      { time_buf[5]++;
  206.       if( time_buf[5] ==60)
  207.        time_buf[5]=0;
  208.       disp_reset();
  209.      }
  210.      if(sum==6)//秒
  211.      {time_buf[6]++;
  212.       if( time_buf[6] ==60)
  213.        time_buf[6]=0;
  214.       disp_reset();
  215.      }
  216.      if(sum==7)//星期
  217.      {  time_buf[7]++;
  218.       if( time_buf[7] ==7)
  219.        time_buf[7]=0;
  220.       disp_reset();
  221.       
  222.      }
  223.     }

  224.    }
  225. }
  226. }

  227. void main(void) {
  228. unsigned char temp;
  229. PORTA = 0xFF;    /*打開上拉*/
  230. DDRA = 0x00;    /*方向輸入*/
  231. PORTB = 0xF0;    /*電平設置*/
  232. DDRB = 0xFF;    /*方向輸出*/
  233. PORTC = 0x7F;
  234. DDRC = 0x80;
  235. PORTD = 0xFF;
  236. DDRD = 0x00;
  237.    DDRD &= ~BIT(7);
  238.    PORTD &= ~BIT(7);
  239.    DDRC |=BIT(6);  //設置輸出
  240.    PORTC &= ~BIT(6);  //L:serial mode 串行
  241.    DDRC &= ~BIT(7);
  242.    PORTC &= ~BIT(7);

  243. delay_ms(20);
  244. LCD_Init();
  245. ds1302_init();
  246. delay_ms(10);
  247. ds1302_write_time();
  248. while (1) {
  249.        scanner();
  250.       if(!keyflag)
  251.     {
  252.    delay_ms(20);
  253.    ds1302_read_time();
  254.       disp_reset();
  255.    }   
  256.   }
  257. }
復制代碼


回復

使用道具 舉報

ID:82781 發表于 2015-6-13 23:23 | 顯示全部樓層
DS1302.H包括如下
  1. #include "iom16v.h"
  2. /*復位腳*/
  3. #define RST_CLR PORTC &= ~(1 << PC4)/*電平置低*/
  4. #define RST_SET PORTC |= (1 << PC4)/*電平置高*/
  5. #define RST_IN DDRC &= ~(1 << PC4)/*方向輸入*/
  6. #define RST_OUT DDRC |= (1 << PC4)/*方向輸出*/
  7. /*雙向數據*/
  8. #define IO_CLR PORTC &= ~(1 << PC3)/*電平置低*/
  9. #define IO_SET PORTC |= (1 << PC3)/*電平置高*/
  10. #define IO_R PINC & (1 << PC3)/*電平讀取*/
  11. #define IO_IN DDRC &= ~(1 << PC3)/*方向輸入*/
  12. #define IO_OUT DDRC |= (1 << PC3)/*方向輸出*/
  13. /*時鐘信號*/
  14. #define SCK_CLR PORTC &= ~(1 << PC2)/*時鐘信號*/
  15. #define SCK_SET PORTC |= (1 << PC2)/*電平置高*/
  16. #define SCK_IN DDRC &= ~(1 << PC2)/*方向輸入*/
  17. #define SCK_OUT DDRC |= (1 << PC2)/*方向輸出*/
  18. #define ds1302_sec_add   0x80  //秒數據地址
  19. #define ds1302_min_add   0x82  //分數據地址
  20. #define ds1302_hr_add   0x84  //時數據地址
  21. #define ds1302_date_add   0x86  //日數據地址
  22. #define ds1302_month_add  0x88  //月數據地址
  23. #define ds1302_day_add   0x8a  //星期數據地址
  24. #define ds1302_year_add   0x8c  //年數據地址
  25. #define ds1302_control_add  0x8e  //控制數據地址
  26. #define ds1302_charger_add  0x90      
  27. #define ds1302_clkburst_add  0xbe
  28. unsigned char time_buf[8] = {0x14,0x08,0x09,0x08,0x16,0x15,0x00,0x02};
  29. /*向DS1302寫入一字節數據*/
  30. void ds1302_write_byte(unsigned char addr, unsigned char d) {
  31. unsigned char i;
  32. RST_SET;     /*啟動DS1302總線*/

  33. /*寫入目標地址:addr*/
  34. IO_OUT;
  35. addr = addr & 0xFE;/*最低位置零*/
  36. for (i = 0; i < 8; i ++) {
  37.   if (addr & 0x01) {
  38.    IO_SET;
  39.    }
  40.   else {
  41.    IO_CLR;
  42.    }
  43.   SCK_SET;
  44.   SCK_CLR;
  45.   addr = addr >> 1;
  46.   }

  47. /*寫入數據:d*/
  48. IO_OUT;
  49. for (i = 0; i < 8; i ++) {
  50.   if (d & 0x01) {
  51.    IO_SET;
  52.    }
  53.   else {
  54.    IO_CLR;
  55.    }
  56.   SCK_SET;
  57.   SCK_CLR;
  58.   d = d >> 1;
  59.   }
  60. RST_CLR;     /*停止DS1302總線*/
  61. }
  62. /*從DS1302讀出一字節數據*/
  63. unsigned char ds1302_read_byte(unsigned char addr) {
  64. unsigned char i;
  65. unsigned char temp,  dat1,dat2 ;
  66. RST_SET;     /*啟動DS1302總線*/
  67. /*寫入目標地址:addr*/
  68. IO_OUT;
  69. addr = addr | 0x01;/*最低位置高*/
  70. for (i = 0; i < 8; i ++) {
  71.   if (addr & 0x01) {
  72.    IO_SET;
  73.    }
  74.   else {
  75.    IO_CLR;
  76.    }
  77.   SCK_SET;
  78.   SCK_CLR;
  79.   addr = addr >> 1;
  80.   }

  81. /*輸出數據:temp*/
  82. IO_IN;
  83. for (i = 0; i < 8; i ++) {
  84.   temp = temp >> 1;
  85.   if (IO_R) {
  86.    temp |= 0x80;
  87.    }
  88.   else {
  89.    temp &= 0x7F;
  90.    }
  91.   SCK_SET;
  92.   SCK_CLR;
  93.   }

  94. RST_CLR;     /*停止DS1302總線*/
  95. /*********原LCD1602中沒有的,現自己加上的 **************/
  96.    dat1=temp/16; //將十六進制數轉換為十進制
  97.    dat2=temp%16;
  98.    temp=dat1*10+dat2;
  99.    /**********************/
  100.   return temp;
  101. }
  102. /*向DS302寫入時鐘數據*/
  103. void ds1302_write_time(void) {
  104. ds1302_write_byte(ds1302_control_add,0x00);   //關閉寫保護
  105. ds1302_write_byte(ds1302_sec_add,0x80);    //暫停
  106. //ds1302_write_byte(ds1302_charger_add,0xa9);   //涓流充電
  107. ds1302_write_byte(ds1302_year_add,time_buf[1]);  //年
  108. ds1302_write_byte(ds1302_month_add,time_buf[2]); //月
  109. ds1302_write_byte(ds1302_date_add,time_buf[3]);  //日
  110. ds1302_write_byte(ds1302_day_add,time_buf[7]);  //周
  111. ds1302_write_byte(ds1302_hr_add,time_buf[4]);  //時
  112. ds1302_write_byte(ds1302_min_add,time_buf[5]);  //分
  113. ds1302_write_byte(ds1302_sec_add,time_buf[6]);  //秒
  114. ds1302_write_byte(ds1302_day_add,time_buf[7]);  //周
  115. ds1302_write_byte(ds1302_control_add,0x80);   //打開寫保護
  116. }
  117. /*從DS302讀出時鐘數據*/
  118. void ds1302_read_time(void)  {
  119. time_buf[1]=ds1302_read_byte(ds1302_year_add);  //年
  120. time_buf[2]=ds1302_read_byte(ds1302_month_add);  //月
  121. time_buf[3]=ds1302_read_byte(ds1302_date_add);  //日
  122. time_buf[4]=ds1302_read_byte(ds1302_hr_add);  //時
  123. time_buf[5]=ds1302_read_byte(ds1302_min_add);  //分
  124. time_buf[6]=(ds1302_read_byte(ds1302_sec_add))&0x7F;//秒
  125. time_buf[7]=ds1302_read_byte(ds1302_day_add);  //周
  126. }
  127. /*DS302初始化函數*/
  128. void ds1302_init(void) {

  129. RST_CLR;   /*RST腳置低*/
  130. SCK_CLR;   /*SCK腳置低*/
  131. RST_OUT;   /*RST腳設置為輸出*/
  132. SCK_OUT;   /*SCK腳設置為輸出*/
  133. }
復制代碼
回復

使用道具 舉報

ID:82781 發表于 2015-6-13 23:24 | 顯示全部樓層
LCD12864.H頭文件如下
  1. /************************************************************
  2.   串行連接操作程序
  3.    對外函數列表:
  4.      void LCD_Init( void ); //初始化
  5.      void LCD_PutStr(unsigned char row,unsigned char col,unsigned char *puts); //寫入文本
  6.      void LCD_PutBMP(unsigned char *puts); //寫入半屏圖片
  7.   void Disp_Img(unsigned const char *img)  //寫整屏圖片
  8.      void LCD_ClearTXT( void ); //清除文本
  9.      void LCD_ClearBMP( void ); //清除圖片
  10. ***********************************************************/
  11. #define uchar unsigned char
  12. #define uint  unsigned int
  13. #define LCDNOP() NOP();NOP()
  14. //以下配置IO管腳
  15. //========================================================*/
  16. #define OUTLCDSCLK() DDRD |= (1<<6) //設置輸出
  17. #define SETLCDSCLK() PORTD |= (1<<6) //拉高
  18. #define CLRLCDSCLK() PORTD &=~(1<<6) //拉低
  19. #define SEL_CS()  DDRD |=BIT(3);PORTD |=BIT(3) //片選拉高
  20. #define CLR_CS()  DDRD |=BIT(3);PORTD &= ~BIT(3) //片選拉低
  21. #define OUTLCDSID() DDRD |= (1<<4) //設置輸出
  22. #define INLCDSID() DDRD &= ~(1 << 4); PORTD |= (1 << 4) //設置輸入
  23. #define SETLCDSID() PORTD |= (1 << 4) //拉高
  24. #define CLRLCDSID() PORTD &= ~(1 << 4) //拉低
  25. #define GETLCDSID() ((PIND & BIT(4)) >> 4) //讀IO值
  26. const unsigned char AC_TABLE[]={
  27. 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,        //第一行漢字位置
  28. 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,        //第二行漢字位置
  29. 0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,        //第三行漢字位置
  30. 0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,        //第四行漢字位置
  31. };
  32. unsigned char  str2[]="歡迎光臨sonsan!!";
  33. unsigned char  str1[]="黃河遠上白云間,一片孤城萬仞山。羌笛何須怨楊柳,春風不度玉門關。";

  34. //維捷登測試架專用延時函數
  35. void DelayKey(uint ms)
  36. {                           
  37.     uint i;
  38.     while(ms--)   
  39.    {
  40.      for(i=1;i<(uint)(1*143-2);i++) //1為1MHZ
  41.          ;
  42.    }
  43. }
  44. //串口發送一個字節
  45. void LCD_WriteByte(unsigned char Dbyte)
  46. {
  47.     unsigned char i;
  48.     OUTLCDSCLK();
  49.     OUTLCDSID();
  50.         for(i=0;i<8;i++)
  51.         {
  52.         CLRLCDSCLK();
  53.                 Dbyte=Dbyte<<1;        //左移一位
  54.         if (SREG & 1)
  55.             SETLCDSID();
  56.         else
  57.             CLRLCDSID();
  58.         SETLCDSCLK();
  59.                 LCDNOP();
  60.         CLRLCDSCLK();
  61.         }
  62.     return;
  63. }
  64. //串口接收一個字節
  65. //僅在讀取數據的時候用到
  66. //而讀出的數據是一次只能讀出4bit的
  67. unsigned char LCD_ReadByte(void)
  68. {
  69.         unsigned char i,temp1,temp2;
  70.         temp1=temp2=0;
  71.     OUTLCDSCLK();
  72.     INLCDSID();
  73.         for(i=0;i<8;i++)
  74.         {
  75.                 temp1=temp1<<1;
  76.         CLRLCDSCLK();
  77.         LCDNOP();
  78.                 SETLCDSCLK();
  79.         LCDNOP();
  80.                 CLRLCDSCLK();
  81.                 if(GETLCDSID()) temp1++;
  82.         }
  83.         for(i=0;i<8;i++)
  84.         {
  85.                 temp2=temp2<<1;
  86.                 CLRLCDSCLK();
  87.         LCDNOP();
  88.                 SETLCDSCLK();
  89.         LCDNOP();
  90.                 CLRLCDSCLK();
  91.                 if(GETLCDSID()) temp2++;
  92.         }
  93.         return ((0xf0&temp1)+(0x0f&temp2));
  94. }
  95. void LCD_CheckBusy( void )
  96. {
  97.         LCDNOP();
  98.     return;
  99.     do   LCD_WriteByte(0xfc);        //11111,RW(1),RS(0),0
  100.         while(0x80&LCD_ReadByte());        //BF(.7)=1 Busy
  101. }
  102. void LCD_WriteCmd( unsigned char Cbyte )
  103. {
  104.         SEL_CS();
  105.         LCD_CheckBusy();
  106.         LCD_WriteByte(0xf8);                 //11111,RW(0),RS(0),0
  107.         LCD_WriteByte(0xf0&Cbyte);        //高四位
  108.   DelayKey(5);
  109.         LCD_WriteByte(0xf0&Cbyte<<4);//低四位(先執行<<)
  110.   DelayKey(5);
  111.         CLR_CS();
  112. }
  113. void LCD_WriteData( unsigned char Dbyte )
  114. {
  115.         SEL_CS();
  116.         LCD_CheckBusy();
  117.         LCD_WriteByte(0xfa);                 //11111,RW(0),RS(1),0
  118.         LCD_WriteByte(0xf0&Dbyte);        //高四位
  119.   DelayKey(5);
  120.         LCD_WriteByte(0xf0&Dbyte<<4);//低四位(先執行<<)
  121.   DelayKey(5);
  122.          CLR_CS();
  123. }
  124. /*顯示屏單字符寫入函數*/
  125. /*void LCD_write_char(unsigned char x,unsigned char y,unsigned char *data) {
  126. switch (y)
  127.    {
  128.     case 0:
  129.         LCD_WriteCmd(0x80 + x);
  130.            break;
  131.        case 1:
  132.         LCD_WriteCmd(0x90 + x);
  133.            break;
  134.        case 2:
  135.         LCD_WriteCmd(0x88 + x);
  136.            break;
  137.        case 3:
  138.         LCD_WriteCmd(0x98 + x);
  139.            break;
  140.       default:
  141.        break;
  142.       }
  143.     LCD_WriteData(*data);  
  144. }*/
  145. /**********************************************************
  146. ;子程序名:void write_single(uchar y,uchar x,uchar *p)
  147. ;功    能:寫單個字符
  148. ;說    明:直接調用
  149. ;調    用:write_single(uchar y,uchar x,uchar *p)
  150. ;**********************************************************/
  151. void write_single(uchar y,uchar x,uchar *p)
  152. {
  153. switch (y)
  154. {
  155.    case 1:LCD_WriteCmd(0x80+x-1);break;
  156.    case 2:LCD_WriteCmd(0x90+x-1);break;
  157.    case 3:LCD_WriteCmd(0x88+x-1);break;
  158.    case 4:LCD_WriteCmd(0x98+x-1);break;
  159.    default:break;
  160. }
  161. LCD_WriteData(*p);
  162. }

  163. unsigned char LCD_ReadData( void )
  164. {
  165.         LCD_CheckBusy();
  166.         LCD_WriteByte(0xfe);                 //11111,RW(1),RS(1),0
  167.         return LCD_ReadByte();
  168. }
  169. void LCD_Init( void )
  170. {   
  171.         DelayKey(2);
  172.         LCD_WriteCmd(0x30);        //8BitMCU,基本指令集合
  173.   DelayKey(2);
  174.   LCD_WriteCmd(0x30);        //8BitMCU
  175.   DelayKey(5);
  176.   LCD_WriteCmd(0x0C);        //顯示ON,游標OFF,游標位反白OFF
  177.   DelayKey(5);
  178.         LCD_WriteCmd(0x01);        //清屏,AC歸0
  179.   DelayKey(5);
  180.         LCD_WriteCmd(0x02);        // AC歸0,不改變DDRAM內容
  181.   DelayKey(5);
  182.          LCD_WriteCmd(0x06);        //寫入時,游標右移動
  183.    DelayKey(2);
  184.         //LCD_WriteCmd(0x80);
  185. }
  186. //文本區清RAM函數
  187. void LCD_ClearTXT( void )
  188. {
  189.         unsigned char i;
  190.         LCD_WriteCmd(0x30);        //8BitMCU,基本指令集合
  191.   DelayKey(5);
  192.         LCD_WriteCmd(0x80);        //AC歸起始位
  193.   DelayKey(5);
  194.         for(i=0;i<64;i++)
  195.         LCD_WriteData(0x20);
  196. }
  197. //圖形區和文本區顯示在兩個不同的RAM區
  198. //圖形區清RAM函數
  199. void LCD_ClearBMP( void )
  200. {
  201.         unsigned char i,j;
  202.         LCD_WriteCmd(0x34);        //8Bit擴充指令集,即使是36H也要寫兩次
  203.         LCD_WriteCmd(0x36);        //繪圖ON,基本指令集里面36H不能開繪圖
  204.         for(i=0;i<32;i++)                 //12864實際為256x32
  205.         {
  206.                 LCD_WriteCmd(0x80|i);        //行位置
  207.                 LCD_WriteCmd(0x80);        //列位置
  208.                 for(j=0;j<32;j++)                 //256/8=32 byte
  209.                         LCD_WriteData(0);
  210.         }
  211. }
  212. void LCD_PutStr(unsigned char row,unsigned char col,unsigned char *puts)
  213. {
  214.         LCD_WriteCmd(0x30);        //8BitMCU,基本指令集合
  215.         LCD_WriteCmd(AC_TABLE[8*row+col]);        //起始位置
  216.         while(*puts != '\0')        //判斷字符串是否顯示完畢
  217.         {
  218.                 if(col==8)                 //判斷換行
  219.                 {                 //若不判斷,則自動從第一行到第三行
  220.                          col=0;
  221.                          row++;
  222.                 }
  223.                 if(row==4) row=0;        //一屏顯示完,回到屏左上角
  224.                 LCD_WriteCmd(AC_TABLE[8*row+col]);
  225.                 LCD_WriteData(*puts);        //一個漢字要寫兩次
  226.                 puts++;
  227.                 if (*puts != '\0')
  228.                 {
  229.                         LCD_WriteData(*puts);
  230.       puts++;
  231.                 }else{break;}
  232.                 col++;
  233.         }
  234. }
  235. void LCD_PutBMP(unsigned const char *puts)  //必須加const 只能寫上下半屏相同的圖片
  236. {
  237.         unsigned int x=0;
  238.         unsigned char i,j;
  239.         LCD_WriteCmd(0x34);        //8Bit擴充指令集,即使是36H也要寫兩次
  240.         LCD_WriteCmd(0x36);        //繪圖ON,基本指令集里面36H不能開繪圖
  241.         for(i=0;i<32;i++)                 //12864實際為256x32
  242.         {
  243.                 LCD_WriteCmd(0x80|i);        //行位置
  244.                 LCD_WriteCmd(0x80);        //列位置
  245.                 for(j=0;j<32;j++)        //256/8=32 byte
  246.                 {                 //列位置每行自動增加
  247.                          LCD_WriteData(puts[x]);
  248.        x++;
  249.                 }
  250.         }
  251. }

  252. void Disp_Img(unsigned const char *img)  //寫整屏圖片
  253. { unsigned int j=0;
  254.    unsigned char x,y,i;
  255.        for(i=0;i<9;i+=8)
  256.        for(y=0;y<32;y++)/*原來 為 y<26 ,上下兩個半屏不能正常對接顯示,導致顯示的圖片中間有空隙*/
  257.          for(x=0;x<8;x++)
  258.          { LCD_WriteCmd(0x36);//功能設置---8BIT控制界面,擴充指令集
  259.             LCD_WriteCmd(y+0x80);        //行地址
  260.             LCD_WriteCmd(x+0x80+i);     //列地址
  261.             LCD_WriteCmd(0x30);
  262.             LCD_WriteData(img[j++]);
  263.             LCD_WriteData(img[j++]);
  264.          }  
  265.          
  266. }

  267. //維捷登測試用點陣顯示
  268. void DisplayDots(unsigned char DotByte)
  269. {
  270.      unsigned char i,j;
  271.      LCD_WriteCmd(0x34);      //8Bit擴充指令集,即使是36H也要寫兩次
  272.      LCD_WriteCmd(0x36);      //繪圖ON,基本指令集里面36H不能開繪圖
  273.      for(i=0;i<32;i++)            //12864實際為256x32
  274.      {
  275.            LCD_WriteCmd(0x80|i);      //行位置
  276.            LCD_WriteCmd(0x80);      //列位置
  277.            for(j=0;j<32;j++)      //256/8=32 byte
  278.            {            //列位置每行自動增加
  279.                  LCD_WriteData(DotByte);                  
  280.            }
  281.            DotByte=~DotByte;
  282.      }
  283. }

  284. //********************************************************//
  285. //***** 轉換的文件:E:\!Program\!BmpSample\25632.bmp
  286. //***** 源圖形寬度 * 高度:256 * 32
  287. //***** 調整后寬度 * 高度:256 * 32
  288. //***** 字模格式:橫向取模,冗余模式,字節正序,正色取模,
  289. //***** 點陣轉換時間:2005/03/ 2   16:4:32
  290. //***** 位圖點陣占用1024字節
  291. //********************************************************//
  292. flash  unsigned char bmp1[]=  
  293. {
  294. 0x00,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,
  295. 0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0xC0,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
  296. 0x00,0x00,0x00,0x00,0x01,0x07,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,
  297. 0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,
  298. 0x00,0x00,0x00,0x00,0x8E,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,
  299. 0x00,0x00,0x00,0x04,0xE0,0x00,0x00,0x00,0x00,0x60,0x00,0x04,0x00,0x00,0x00,0x00,
  300. 0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x01,0x88,0x00,0x00,0x00,
  301. 0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x08,0x38,0xE0,0x00,0x00,0x39,0x00,0x00,0x00,
  302. 0x00,0x00,0x06,0x60,0x00,0x00,0x00,0x0C,0x1C,0xC0,0x00,0x00,0x04,0x80,0x00,0x00,
  303. 0x00,0x00,0x09,0x80,0x00,0x00,0x00,0x0C,0x30,0xC0,0x00,0x00,0x01,0xB0,0x00,0x00,
  304. 0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x08,0x7B,0x80,0x08,0x00,0x00,0x48,0x00,0x00,
  305. 0x00,0x00,0x58,0x00,0x01,0x86,0x00,0x00,0x03,0x80,0x0C,0x00,0x00,0x1E,0x00,0x00,
  306. 0x00,0x00,0x60,0x00,0x01,0x86,0x00,0x00,0x03,0x00,0x04,0x00,0x00,0x07,0x80,0x00,
  307. 0x00,0x00,0x80,0x00,0x01,0x86,0x00,0x00,0x03,0x00,0x04,0x00,0x00,0x07,0xC0,0x00,
  308. 0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,
  309. 0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x78,0x00,
  310. 0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x78,0x00,
  311. 0x00,0x78,0x30,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0x1E,0x00,
  312. 0x00,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x07,0x00,0x1F,0x00,
  313. 0x01,0xE0,0x00,0xC7,0x80,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x06,0x00,0x07,0x00,
  314. 0x01,0xE0,0x00,0x19,0xC0,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x1C,0x00,0x07,0x00,
  315. 0x03,0x80,0x00,0x8F,0x80,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x0C,0x00,0x01,0xC0,
  316. 0x03,0x80,0x00,0x03,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,
  317. 0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,
  318. 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,
  319. 0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,
  320. 0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x78,
  321. 0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,
  322. 0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,
  323. 0x1E,0x00,0x3E,0x00,0x00,0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x38,0x00,0x7C,
  324. 0x1E,0x00,0x36,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00,0x18,0x00,0x7C,
  325. 0x1E,0x00,0x1E,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x1C,0x00,0x7C,
  326. 0x1E,0x00,0x1C,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x78,
  327. 0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,
  328. 0x1E,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,
  329. 0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x78,
  330. 0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF8,
  331. 0x07,0x00,0x00,0x00,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,
  332. 0x07,0x80,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,
  333. 0x07,0x80,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xE0,
  334. 0x07,0xC0,0x00,0x70,0x00,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x07,0xC0,
  335. 0x03,0xE0,0x00,0xF8,0x00,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x0C,0x04,0x07,0xC0,
  336. 0x01,0xE0,0x00,0xF8,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x3E,0x00,0x07,0xC0,
  337. 0x00,0xF0,0x08,0x78,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x1F,0x80,
  338. 0x00,0xF8,0x20,0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x1E,0x00,
  339. 0x00,0x3C,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7C,0x00,
  340. 0x00,0x3E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFC,0x00,
  341. 0x00,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF8,0x00,
  342. 0x00,0x0F,0xC0,0x00,0x00,0x38,0x00,0x00,0x00,0x00,0x1C,0x00,0x00,0x07,0xF0,0x00,
  343. 0x00,0x07,0xE0,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x1E,0x00,0x00,0x0F,0xE0,0x00,
  344. 0x00,0x01,0xF8,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x1F,0x80,0x00,
  345. 0x00,0x00,0xFE,0x00,0x00,0x40,0x00,0x07,0x80,0x00,0x1E,0x00,0x00,0x7F,0x00,0x00,
  346. 0x00,0x00,0x3F,0x80,0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x03,0xF8,0x00,0x00,
  347. 0x00,0x00,0x0F,0xE0,0x02,0x00,0x00,0x06,0xC0,0x00,0x00,0x00,0x0F,0xE0,0x00,0x00,
  348. 0x00,0x00,0x03,0xF8,0x00,0x00,0x00,0x03,0x80,0x00,0x08,0x00,0x3F,0xC0,0x00,0x00,
  349. 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x01,0xFE,0x00,0x00,0x00,
  350. 0x00,0x00,0x00,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xF8,0x00,0x00,0x00,
  351. 0x00,0x00,0x00,0x03,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x7F,0xC0,0x00,0x00,0x00,
  352. 0x00,0x00,0x00,0x00,0x7F,0xE0,0x00,0x00,0x00,0x00,0x0F,0xFC,0x00,0x00,0x00,0x00,
  353. 0x00,0x00,0x00,0x00,0x07,0xFF,0x80,0x00,0x00,0x01,0xFF,0xF0,0x00,0x00,0x00,0x00,
  354. 0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xE0,0x3F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,
  355. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  356. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  357. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  358. };
  359. #pragma data:data      //設置回到數據存儲器區
復制代碼
回復

使用道具 舉報

ID:103094 發表于 2016-1-23 11:10 | 顯示全部樓層
可以告訴我哪些對應具體lcd的口,么
回復

使用道具 舉報

ID:117568 發表于 2016-4-29 18:34 | 顯示全部樓層
硬件接線怎以連呀?
回復

使用道具 舉報

ID:147078 發表于 2016-11-9 23:23 來自手機 | 顯示全部樓層
不錯 有圖紙嗎
回復

使用道具 舉報

ID:146539 發表于 2016-12-5 17:20 | 顯示全部樓層
來個圖
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 最新黄色在线观看 | 在线观看 亚洲 | 欧洲av一区 | 国产一级视频在线播放 | 亚洲国产一区二区三区四区 | 国产精品久久久久久久久久久久午夜片 | 91视频进入| 色婷婷综合成人av | 欧美aa在线 | 日韩在线视频一区 | 国产精品无码专区在线观看 | 91精品国产欧美一区二区成人 | 国产精品久久久久久久久久三级 | 中文字幕在线观看成人 | 精品久久一区二区三区 | 久久精品欧美视频 | 精品国产乱码久久久久久a丨 | 国产日韩欧美一区 | 福利片在线观看 | 国产一级一级国产 | 国产激情精品一区二区三区 | 男女羞羞视频免费 | 亚洲精品一区二区三区中文字幕 | 操久久 | 欧美在线激情 | 日韩午夜 | 爱草在线| 成人小视频在线免费观看 | 成人av一区| 色伊人久久 | 成人做爰www免费看 午夜精品久久久久久久久久久久 | 中文字幕一区二区在线观看 | 精品亚洲一区二区三区 | 国产丝袜一区二区三区免费视频 | 成人欧美一区二区三区在线播放 | 日韩在线观看中文字幕 | 欧美一区二区免费视频 | 久久精品视频免费观看 | 动漫www.被爆羞羞av44 | 日韩人体在线 | 国产网站在线免费观看 |