void openlcd(void) { LCD_DIR = 0xFF; /* configure LCD_DAT port for output */ delay_1ms(100); /* Wait for LCD to be ready */ put2lcd(0x28,CMD); /* set 4-bit data, 2-line display, 5x7 font */ put2lcd(0x0F,CMD); /* turn on display, cursor, blinking */ put2lcd(0x06,CMD); /* move cursor right */ put2lcd(0x01,CMD); /* clear screen, move cursor to home */ delay_1ms(2); /* wait until "clear display" command is complete */ }
/*LCD?????*/ void lcd_init() { LCD_PSB=1; write_cmd(0x30); delay_1ms(5); write_cmd(0x0C); delay_1ms(5); write_cmd(0x01); delay_1ms(5); }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { /* GPIO clock enable */ rcu_periph_clock_enable(RCU_GPIOA); rcu_periph_clock_enable(RCU_GPIOB); rcu_periph_clock_enable(RCU_GPIOC); rcu_periph_clock_enable(RCU_GPIOF); /* delay time initialize */ systick_config(); /* configure the CEC peripheral */ cec_config(); /* configure the EXTI */ gd_eval_keyinit(KEY_TAMPER, KEY_MODE_EXTI); #ifdef GD32F130_150 gd_eval_keyinit(KEY_USER, KEY_MODE_EXTI); #elif defined(GD32F170_190) gd_eval_keyinit(KEY_WAKEUP, KEY_MODE_EXTI); #endif /* GD32F130_150 */ /* LED1 LED2 initialize */ gd_eval_ledinit(LED1); gd_eval_ledinit(LED2); gd_eval_ledoff(LED1); gd_eval_ledoff(LED2); /* main loop */ while(1) { /* wait receive data */ while(rcvstatus==0); if(rcvstatus == 1) { if((rcvdata[1]==0xA5)&&(rcvdata[2]==0x5A)) { gd_eval_ledon(LED1); delay_1ms(10); gd_eval_ledoff(LED1); } if((rcvdata[1]==0x5A)&&(rcvdata[2]==0xA5)) { gd_eval_ledon(LED2); delay_1ms(10); gd_eval_ledoff(LED2); } } /* a reception error occured */ rcvstatus = 0; } }
/*RS=L,RW=L,E=???,DO-D7=???*/ void write_cmd(uchar cmd) { LCD_RS =1; LCD_RW =0; LCD_EN=0; P0=cmd; delay_1ms(5); LCD_EN=1; delay_1ms(5); LCD_EN=0; }
/*RS=L,RW=L,E=???,DO-D7=??*/ void write_dat(uchar dat) { LCD_RS =1; LCD_RW =0; LCD_EN=0; P1=dat; delay_1ms(5); LCD_EN=1; delay_1ms(5); LCD_EN=0; }
// delay about ms milliseconds void mdelay(int ms) { static int loop_count = -1; if (hwconfig_simulation_p()) return; if (loop_count < 0){ // set correct loop_count static unsigned short lc[8] = { 0, LOOPCNT(1), LOOPCNT(2), LOOPCNT(3), LOOPCNT(4), LOOPCNT(5), LOOPCNT(6), LOOPCNT(7) }; loop_count = lc[hwconfig_wishbone_divisor() & 0x7]; } int i; for (i = 0; i < ms; i++) delay_1ms(loop_count); }
void TSLCDRst(void) //pulse reset signal to LCD { Orb(LCD_RST_DPRT,LCD_RST_PIN); Clrb(LCD_RST_PRTC,LCD_RST_PIN); delay_1ms(50); Setb(LCD_RST_PRTS,LCD_RST_PIN); }
void delay_ms(unsigned int n) { unsigned int i; for (i=0; i<n; ++i) delay_1ms(); }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { /* system clocks configuration */ irc40k_config(); systick_config(); gd_eval_ledinit(LED2); gd_eval_keyinit(KEY_TAMPER,KEY_MODE_EXTI); delay_1ms(50); /* enable write access to FWDGT_PSC and FWDGT_RLD registers. FWDGT counter clock: 40KHz(IRC40K) / 64 = 0.625 KHz */ fwdgt_config(625,FWDGT_PSC_DIV64); fwdgt_enable(); /* check if the system has resumed from FWDGT reset */ if (RESET != rcu_flag_get(RCU_FLAG_FWDGTRST)){ gd_eval_ledon(LED2); rcu_reset_flag_clear(); while(1); }else{ gd_eval_ledoff(LED2); } while (1); }
void delay_ms(uint16_t delay) { uint16_t i; for (i = 0; i < delay; i++) { delay_1ms(); } }
uint8_t closeNet() { uint16_t timeout = 0; memset( GPRS.receive, 0, ( size_t )GPRS_RX_BUFFER_SIZE ); GPRS.receive_count = 0; printf("AT+SAPBR=0,1\r\n"); while(GPRS.receive_count < 0x14) { timeout++; delay_1ms(); if(timeout>TIME_OUT) { return ERROR; } } for(uint8_t i=GPRS.receive_count;i>0;i--) { if((GPRS.receive[i] == '\r') && (GPRS.receive[i+1] == '\n') && (GPRS.receive[i+2] == 'O') && (GPRS.receive[i+3] == 'K') && (GPRS.receive[i+4] == '\r') && (GPRS.receive[i+5] == '\n') ) { return OK; } } return ERROR; }
uint8_t setURL(uint32_t address,uint8_t data_type, uint16_t data) { uint16_t timeout = 0; memset( GPRS.receive, 0, ( size_t )GPRS_RX_BUFFER_SIZE ); GPRS.receive_count = 0; printf("AT+HTTPPARA=\"URL\","); printf("http://www.xiaoxiami.space/info/manhole-post/"); printf("?address=%d&data_type=%d&data=%d\r\n",address,data_type,data); while(GPRS.receive_count < 0x66) { timeout++; delay_1ms(); if(timeout>TIME_OUT) { return ERROR; } } for(uint8_t i=GPRS.receive_count;i>50;i--) { if((GPRS.receive[i] == '\r') && (GPRS.receive[i+1] == '\n') && (GPRS.receive[i+2] == 'O') && (GPRS.receive[i+3] == 'K') && (GPRS.receive[i+4] == '\r') && (GPRS.receive[i+5] == '\n') ) { return OK; } } return ERROR; }
void v_lcd_init() { v_lcd_gpio_init(); lcd_init(); v_lcd_backlight(1); delay_1ms(2); }
void main() { hd_writeonechar(0xa4); lcd_writecd(0,0x0c); lcd_writecd(0,0x01); delay_1ms(5); lcd_string(0x96,"0."); while(1) { if(!hd_key) { key_process(hd_keyconvert(hd_read(0x15))); }while(!hd_key); delay_1ms(5); } }
void delay_ms(unsigned int ms) { while(ms) { delay_1ms(); ms--; } }
void digit(U8 add,U8 dat) { P2=~(1<<(add-1)); OE=0; P0=table[dat]; clk=0; clk=1; delay_1ms(5); }
void digit(U16 add,U16 dat) { P2=~(1<<(add-1)); OE=0; P0=dat; clk=0; clk=1; delay_1ms(5); }
void lcd_init() { delay_1ms(100); send_command(0x30); send_command(0x04); send_command(0x0c); send_command(0x0); send_command(0x02); send_command(0x80); }
static void sld_hw_clear(void) { sld_hw_dbus_write(0x01, RS_INST); /* if (sld_hw_busy()) { */ /* delay_1ms(); */ /* } */ delay_1ms(); }
void LCD_init(void) { lcd_DB0_tris = 0; lcd_DB1_tris = 0; lcd_DB2_tris = 0; lcd_DB3_tris = 0; lcd_DB4_tris = 0; // Data0 lcd_DB5_tris = 0; // Data1 lcd_DB6_tris = 0; // Data2 lcd_DB7_tris = 0; // Data3 lcd_RW_tris = 0; lcd_RS_tris = 0; lcd_E_tris = 0; lcd_E = 0; lcd_RW = 0; delay_1ms(40); // > 40ms Init LCD_4write(0, 0, 0, 0, 1, 1); delay_1ms(5); LCD_4write(0, 0, 0, 0, 1, 1); delay_1ms(5); LCD_4write(0, 0, 0, 0, 1, 1); // Function set - 8 bits interface delay_1ms(5); LCD_4write(0, 0, 0, 0, 1, 0); delay_10us(25); /* DL is 4bits, N is 2 row, F is 0 */ LCD_8write(0, 0, 0, 0, 1, 0, 1, 0, 0, 0); delay_10us(25); /* Diplay on, Cursor, Blink */ LCD_8write(0, 0, 0, 0, 0, 0, 1, 1, 1, 1); delay_10us(25); /* Clear LCD */ LCD_8write(0, 0, 0, 0, 0, 0, 0, 0, 0, 1); delay_1ms(25); /* Set Entry Mode */ LCD_8write(0, 0, 0, 0, 0, 0, 0, 1, 1, 0); delay_1ms(25); while ((LCD_get_BF() & 0x80) == 1) ; delay_1ms(40); }
void digit(U8 add,U8 dat) { bit bee=beep; P2=~(1<<(add-1)); OE=0; P0=table[dat]; clk=0; clk=1; beep=bee; delay_1ms(5); }
void DHT_Start(){ DHT11_SIGNAL_CONFIG = 0; // PORT RA1 as OUTPUT from MCU DHT11_SIGNAL = 1; delay_10us(5); DHT11_SIGNAL = 0; delay_1ms(30); DHT11_SIGNAL = 1; delay_10us(3); DHT11_SIGNAL = 0; delay_1us(1); DHT11_SIGNAL_CONFIG = 1; // PORT RA1 as INPUT to MCU }
void main() { U8 i; lcd_writecd(CMD,0x0c); lcd_string(0x87,"Welcome"); lcd_string(0x97,"Good Luck!"); while(1) { lcd_writecd(CMD,0x18); delay_1ms(1000); } }
int znajdz_id(int num)//num jest szukanym id { // falsz=0, jesli >0 to jest to numer rekordu(0-15), blad odczytu eeprom =-1, jesli id nie istnieje=-2 int znaleziono=-2; int i=0; uint16_t adres_id=0;/////?? // char tab[5]={0,0,0,0,0}; uint8_t dane=0xff; int j=0; for (; i < 16 ; i++) { adres_id=adres(i); for(;j<4;j++) { delay_1ms(); delay_1ms(); dane=(Read_24Cxx(adres_id,M2404)); if(dane==0xff)//blad odczytu eeprom { return -1; } else { tab[j]=dane; } adres_id++; } j=0; tab[4]=0; int id_odczytany=atoi(tab); if(num==id_odczytany) { znaleziono=i; break; } }//for return znaleziono; }
void delay_10ms(){ char i; for(i=0; i<9; i++) delay_1ms(); for(i=0; i<59; i++); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); Nop(); }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { uint16_t num = 0; /* system clocks configuration */ rcu_config(); /* systick config: 1ms delay */ systick_config(); /* slcd interface configuration */ slcd_seg_config(); while(1){ slcd_seg_number_display(num++); delay_1ms(1000); } }
/*! \brief main function \param[in] none \param[out] none \retval none */ int main(void) { systick_config(); gd_eval_ledinit(LED1); gd_eval_keyinit(KEY_TAMPER,KEY_MODE_GPIO); while(1){ /* check whether the button is pressed */ if(RESET == gd_eval_keygetstate(KEY_TAMPER)){ delay_1ms(100); /* check whether the button is pressed */ if(RESET == gd_eval_keygetstate(KEY_TAMPER)){ gd_eval_ledtoggle(LED1); } } } }
void main() { U8 second,second_old; lcd_writecd(0,0x0c); lcd_string(0x80,"¡æ"); while(1) { second=rtc_read(0x80); if(second!=second_old) { second_old=second; lcd_writecd(0,0x90); lcd_writecd(1,second/10+'0'); lcd_writecd(1,second%10+'0'); } delay_1ms(5); } }
uint8_t getRequest() { uint16_t timeout = 0; memset( GPRS.receive, 0, ( size_t )GPRS_RX_BUFFER_SIZE ); GPRS.receive_count = 0; printf("AT+HTTPACTION=0\r\n"); while(GPRS.receive_count < 0x30) { timeout++; delay_1ms(); if(timeout>5000) { return ERROR; } } for(uint8_t i=30;i<50;i++) { if((GPRS.receive[i] == 'H') && (GPRS.receive[i+1] == 'T') && (GPRS.receive[i+2] == 'T') && (GPRS.receive[i+3] == 'P') && (GPRS.receive[i+4] == 'A') && (GPRS.receive[i+5] == 'C') && (GPRS.receive[i+6] == 'T') && (GPRS.receive[i+7] == 'I') && (GPRS.receive[i+8] == 'O') && (GPRS.receive[i+9] == 'N') && (GPRS.receive[i+10]== ':') && (GPRS.receive[i+11]== '0') && (GPRS.receive[i+12]== ',') && (GPRS.receive[i+13]== '2') && (GPRS.receive[i+14]== '0') && (GPRS.receive[i+15]== '0') && (GPRS.receive[i+16]== ',') ) { return OK; } } return ERROR; }
void main() { U16 temp1,temp1_old,temp2,temp2_old; lcd_writecd(0,0x0c); lcd_string(0x80,"²âÊÔµã1:"); lcd_string(0x90,"²âÊÔµã2:"); uart_init(); while(1) { temp1=temp_read(0); temp2=temp_read(1); if(temp1!=temp1_old || temp2!=temp2_old) { lcd_temp(0x84,temp1); lcd_temp(0x94,temp2); temp1_old=temp1; temp2_old=temp2; } delay_1ms(5); } }