【求助】想做个万年历,正在构想。

2019-03-25 20:26发布

<div><b>【上下文】</b></div>打算用超级电容+太阳能电池供电,所以功率一定要小。本来考虑AVR的,后来欣喜的发现了LPC111x系列。<div>打算用12864的液晶,能够显示基本的时间和日期(公历农历),还能够每天显示几个位图,可以是一些小幽默什么的。</div><div>最好能够加入测光还有测温的感应器件,能够显示光线是否适合读书上网。</div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><span class="Apple-style-span" style="line-height: 22px; "><div style="word-wrap: break-word; line-height: normal; ">除了LPC1114以外,时钟、闪存、图形液晶的选型都是一头雾水,主要是功耗的限制。</div><div style="word-wrap: break-word; line-height: normal; ">假设10法拉是电容的极限,最少在黑暗的条件下坚持20小时,工作电压是2.7~3.6V的话,平均工作电流要限制在0.125mA以内……</div></span></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><br class="Apple-interchange-newline">忘了声明,单片机方面我是菜鸟,除了大学里学的8051以外没有任何经验(大学用编码器锁存器做过简单的数字抢答器,和单片机没任何关系)</div><div>编程方面会用JAVA和Python,面对C应该不是很痛苦。</div><div><br></div><div><b>【求助】</b></div><div>1、请问有没有一种12864图形液晶可以用很低的功耗维持当前的画面呢?</div><div>2、如果有,那么时钟芯片可以每几十秒唤醒MCU然后刷新画面吗?</div><div>3、如果没有,除了把电容换成电池以外还有其他的可能设计吗?</div><div>4、另外请推荐一下比较容易上手的时钟IC和flash,flash4MB就足够了。</div><div>5、网上看到一种串口Flash,M25P32这种型号,读的电流约8mA,不知道是否容易入门……</div><div><br></div><div><b>【这里留给开发过程】</b></div><div><br></div><div><b>【结束】</b></div><div>打算30天左右做出来,外壳估计会很头疼。先感谢各位路过的、顶贴的和回复的大侠了,这厢有礼了。</div> 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
19条回答
elulis
2019-03-27 19:47

  1. #include "LPC11xx.h"
  2. #include "gpio.h"
  3. #include "ssp.h"

  4. /* MX25xx05 SPI FLASH command set*/
  5. #define MX25_WREN        0x06
  6. #define MX25_WRDI        0x04
  7. #define MX25_RDSR        0x05
  8. #define MX25_WRSR        0x01
  9. #define MX25_READ        0x03        // 3bytes addr followed
  10. #define MX25_WRITE        0x02        // 3bytes addr followed, erased to 'ff' requried
  11. #define MX25_PP                MX25_WRITE
  12. #define MX25_CP                0xAD        // continuios program, 3bytes addr followed
  13. #define MX25_SE                0x20        // sector erase 3bytes addr followed
  14. #define MX25_BE                0xD8        // block erase 3bytes addr followed
  15. #define MX25_CE                0x60
  16. #define MX25_DP                0xB9        // Deep Power down
  17. #define MX25_RDP        0xAB        // Release from Deep Power down

  18. #define LED1_on() (GPIOSetValue(0, 1, 0))
  19. #define LED1_off() (GPIOSetValue(0, 1, 1))
  20. #define LED2_on() (GPIOSetValue(1, 8, 0))
  21. #define LED2_off() (GPIOSetValue(1, 8, 1))

  22. #define SSP0_csHigh() (GPIOSetValue(0, 3, 1))
  23. #define SSP0_csLow() (GPIOSetValue(0, 3, 0))

  24. #define SPI_BUFFER_SIZE        256
  25. uint8_t opBuf[4];
  26. uint8_t wrBuf[SPI_BUFFER_SIZE];
  27. uint8_t rdBuf[SPI_BUFFER_SIZE];

  28. void initMingIO(void){
  29.         // init GPIO
  30.         GPIOInit();
  31.         GPIOSetDir(0, 1, 1);        // LED1
  32.         GPIOSetDir(1, 8, 1);        // LED2
  33.         LPC_IOCON->PIO0_3 &= ~0x07;
  34.         GPIOSetValue(0, 3, 1);
  35.         GPIOSetDir(0, 3, 1);        // SSP0 /CS
  36.         // init SSP
  37.         SSP_IOConfig(0);
  38.         SSP_Init(0);
  39.        
  40. }

  41. void printBits(uint8_t value){
  42.         uint32_t i = 0;
  43.         uint8_t v = value;
  44.         uint8_t p;
  45.         for(p=0; p < 8; p ++){
  46.                 LED1_on();
  47.                 if(v & 0x01){
  48.                         LED2_on();
  49.                 }else{
  50.                         LED2_off();
  51.                 }
  52.                 v = v >> 1;
  53.                 for(i=0;i<0x200000;i++);
  54.                 LED2_off();
  55.                 LED1_off();
  56.                 for(i=0;i<0x200000;i++);
  57.         }
  58.         LED1_off();
  59.         LED2_off();
  60.         for(i=0;i<0x200000;i++);
  61. }

  62. /**
  63.    Wait Untill WIP release
  64. **/
  65. void spiFlash_Wait(void){
  66.         uint32_t i;
  67.         uint8_t sr = 0x01;
  68.         while(sr & 0x01){
  69.                 opBuf[0] = MX25_RDSR;
  70.                 SSP0_csLow();
  71.                 SSP_Send(0, (uint8_t *)opBuf, 1);
  72.                 SSP_Receive(0, (uint8_t *)rdBuf, 1);
  73.                 SSP0_csHigh();
  74.                 sr = rdBuf[0];
  75.                 for(i = 0; i < 100; i ++);
  76.         }
  77. }

  78. /**
  79.    Sector Erase 4096 bytes, least 8 bits of addr ignored.
  80. **/
  81. void spiFlash_SE(uint32_t addr){
  82.         spiFlash_Wait();
  83.         // send WREN
  84.         opBuf[0] = MX25_WREN;
  85.         SSP0_csLow();
  86.         SSP_Send(0, (uint8_t *)opBuf, 1);
  87.         SSP0_csHigh();
  88.         spiFlash_Wait();
  89.         // send SE
  90.         opBuf[0] = MX25_SE;
  91.         opBuf[1] = addr >> 16;
  92.         opBuf[2] = addr >> 8;
  93.         opBuf[3] = 0;
  94.         SSP0_csLow();
  95.         SSP_Send(0, (uint8_t *)opBuf, 1);
  96.         SSP0_csHigh();
  97.         spiFlash_Wait();
  98. }

  99. /**
  100.    Page Programming 256 bytes, least 8 bits of addr ignored.
  101. **/
  102. void spiFlash_PP(uint32_t addr){
  103.         spiFlash_Wait();
  104.         // send WREN
  105.         opBuf[0] = MX25_WREN;
  106.         SSP0_csLow();
  107.         SSP_Send(0, (uint8_t *)opBuf, 1);
  108.         SSP0_csHigh();
  109.         spiFlash_Wait();
  110.         // PP 256 bytes
  111.         opBuf[0] = MX25_PP;
  112.         opBuf[1] = addr >> 16;
  113.         opBuf[2] = addr >> 8;
  114.         opBuf[3] = 0;
  115.         SSP0_csLow();
  116.         SSP_Send(0, (uint8_t *)opBuf, 4);
  117.         SSP_Send(0, (uint8_t *)wrBuf, 256);
  118.         SSP0_csHigh();
  119.         spiFlash_Wait();
  120. }

  121. /**
  122.    Page Reading 256 bytes, least 8 bits of addr ignored.
  123. **/
  124. void spiFlash_PR(uint32_t addr){
  125.         spiFlash_Wait();
  126.         opBuf[0] = MX25_READ;
  127.         opBuf[1] = addr >> 16;
  128.         opBuf[2] = addr >> 8;
  129.         opBuf[3] = 0;
  130.         SSP0_csLow();
  131.         SSP_Send(0, (uint8_t *)opBuf, 4);
  132.         SSP_Receive(0, (uint8_t *)rdBuf, 256);
  133.         SSP0_csHigh();
  134. }

  135. void testSpiFlash(void){
  136.         spiFlash_SE(0);
  137.        
  138.         wrBuf[0] = 0x55;
  139.         wrBuf[1] = 0xAA;
  140.         wrBuf[2] = 0x12;
  141.         wrBuf[3] = 0x34;
  142.         spiFlash_PP(0);

  143.         spiFlash_PR(0);
  144.         printBits(rdBuf[0]);
  145.         printBits(rdBuf[1]);
  146.         printBits(rdBuf[2]);
  147.         printBits(rdBuf[3]);
  148. }
复制代码

调用的代码是这样子的

  1. #include "LPC11xx.h"
  2. #include "gpio.h"

  3. #include "ming_io.c"

  4. int main(void){
  5.        
  6.         SystemInit();
  7.        
  8.         initMingIO();

  9.         while(1){
  10.                 testSpiFlash();
  11.         }

  12. }
复制代码
从现在起,我有4MB的闪存可以用咯,开心^ ^
唉,编辑的时候有缩进。编辑完看不到了,严重不是“所见即所得模式”啊~

[ 本帖最后由 elulis 于 2010-11-22 00:56 编辑 ]

一周热门 更多>