Example #1
0
void ST7565_st7565_init(void) {
  // set pin directions
//  pinMode(sid, OUTPUT);
//  pinMode(sclk, OUTPUT);
//  pinMode(a0, OUTPUT);
//  pinMode(rst, OUTPUT);
//  pinMode(cs, OUTPUT);

  // toggle RST low to reset; CS low so it'll listen to us
//  if (cs > 0)
//    digitalWrite(cs, LOW);
  GPIO_ResetBits(GPIOB, GPIO_Pin_9);

//  digitalWrite(rst, LOW);
  GPIO_ResetBits(GPIOB, GPIO_Pin_10);
  DelaymS(500);
//  digitalWrite(rst, HIGH);
  GPIO_SetBits(GPIOB, GPIO_Pin_10);

  // LCD bias select
  ST7565_st7565_command(CMD_SET_BIAS_7);
  // ADC select
  ST7565_st7565_command(CMD_SET_ADC_NORMAL);
  // SHL select
  ST7565_st7565_command(CMD_SET_COM_NORMAL);
  // Initial display line
  ST7565_st7565_command(CMD_SET_DISP_START_LINE);

  // turn on voltage converter (VC=1, VR=0, VF=0)
  ST7565_st7565_command(CMD_SET_POWER_CONTROL | 0x4);
  // wait for 50% rising
  DelaymS(50);

  // turn on voltage regulator (VC=1, VR=1, VF=0)
  ST7565_st7565_command(CMD_SET_POWER_CONTROL | 0x6);
  // wait >=50ms
  DelaymS(50);

  // turn on voltage follower (VC=1, VR=1, VF=1)
  ST7565_st7565_command(CMD_SET_POWER_CONTROL | 0x7);
  // wait
  DelaymS(10);

  // set lcd operating voltage (regulator resistor, ref voltage resistor)
  ST7565_st7565_command(CMD_SET_RESISTOR_RATIO | 0x6);

  // initial display line
  // set page address
  // set column address
  // write display data

  // set up a bounding box for screen updates

  ST7565_updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
}
Example #2
0
void dht11_update(void)
{
              int flag = 1;
            unsigned char dat1, dat2, dat3, dat4, dat5, ck;
	    //主机拉低18ms 
            COM_CLR;
          
	    DelaymS(18);
	    //COM_IN;
	    COM_SET;
            flag = 0;
	    while (COM_R && ++flag);
            if (flag == 0) return;
            
	    //总线由上拉电阻拉高 主机延时20us
	    //主机设为输入 判断从机响应信号  
	    //判断从机是否有低电平响应信号 如不响应则跳出,响应则向下运行	  	    
            flag = 0;
             while (!COM_R && ++flag);
             if (flag == 0) return;
             flag = 0;
             while (COM_R && ++flag);
             if (flag == 0) return;
                  
             
             dat1 = dht11_read_byte();

             dat2 = dht11_read_byte();

             dat3 = dht11_read_byte();
              
    
             dat4 = dht11_read_byte();
              
   
             dat5 = dht11_read_byte();           
                  
              
             ck = dat1 + dat2 + dat3 + dat4;
              
             if (ck == dat5) {
                sTemp = dat3;
                sHumidity = dat1;        
             }
             
#if 1
      //       printf("%02x, %02x, %02x, %02x %02x\r\n", 
      //               dat1, dat2, dat3, dat4, dat5);
             printf("湿度: %u%% 温度: %u℃ \r\n", dat1, dat3);
             gdat1=dat1;
             gdat2=dat3;
#endif	   
}
Example #3
0
void ST7565_display(void) {
  uint8_t col, maxcol, p;

  /*
  Serial.print("Refresh ("); Serial.print(xUpdateMin, DEC); 
  Serial.print(", "); Serial.print(xUpdateMax, DEC);
  Serial.print(","); Serial.print(yUpdateMin, DEC); 
  Serial.print(", "); Serial.print(yUpdateMax, DEC); Serial.println(")");
  */

  for(p = 0; p < 8; p++) {
    /*
      putstring("new page! ");
      uart_putw_dec(p);
      putstring_nl("");
    */
#ifdef enablePartialUpdate
    // check if this page is part of update
    if ( yUpdateMin >= ((p+1)*8) ) {
      continue;   // nope, skip it!
    }
    if (yUpdateMax < p*8) {
      break;
    }
#endif

  DelaymS(1);
    ST7565_st7565_command(CMD_SET_PAGE | pagemap[p]);
    DelaymS(1);//DelayuS(100);


#ifdef enablePartialUpdate
    col = xUpdateMin;
    maxcol = xUpdateMax;
#else
    // start at the beginning of the row
    col = 0;
    maxcol = LCDWIDTH;
#endif

    ST7565_st7565_command(CMD_SET_COLUMN_LOWER | ((col+ST7565_STARTBYTES) & 0xf));
    DelaymS(1);
    ST7565_st7565_command(CMD_SET_COLUMN_UPPER | (((col+ST7565_STARTBYTES) >> 4) & 0x0F));
    DelaymS(1);
    ST7565_st7565_command(CMD_RMW);
    DelaymS(1);//DelayuS(100);
    
    for(; col < maxcol; col++) {
      //uart_putw_dec(col);
      //uart_putchar(' ');
      ST7565_st7565_data(st7565_buffer[(128*p)+col]);
      //DelayuS(10);
    }
  }

#ifdef enablePartialUpdate
  xUpdateMin = LCDWIDTH;// - 1;
  xUpdateMax = 0;
  yUpdateMin = LCDHEIGHT;//-1;
  yUpdateMax = 0;
#endif
}