void get_sensors_state(){ if(PIN_STATE(WATER_LEVER_SENSOR)) { if(regim == DISPLAY_REGIM_DEFAULT) {regim = DISPLAY_REGIM_NO_WATER;} PIN_ON(NO_WATER_LED); PIN_OFF(WATERING_RELAY); }else{ if(PIN_STATE(NO_WATER_LED)) {PIN_OFF(NO_WATER_LED);} } if(PIN_STATE(LIGHT_SENSOR)) { //датчик естественного света - выключаем досветку if(PIN_STATE(LIGHT_RELAY)) {PIN_OFF(LIGHT_RELAY);} }else{ //текущее врем¤ в разрешенном диапазоне использовани¤ досветки RTCTIME rtc_clock; RTC_GetTime(&rtc_clock); u16 now_time = set_low_n_height(rtc_clock.hour, rtc_clock.min); //текущее врем¤ (часы+минуты) //но в заданный промежуток времени if (BKP_ReadBackupRegister(tMORNING_LIGHT_TIME_BKP) < now_time && now_time < BKP_ReadBackupRegister(tEVENING_LIGHT_TIME_BKP)) //с утра до вечера { PIN_ON(LIGHT_RELAY); } } }
void lcd_nokia1100_write_data(uint8_t data) { PIN_ON(LCD_NOKIA_1100_CS); PIN_OFF(LCD_NOKIA_1100_SCLK); PIN_ON(LCD_NOKIA_1100_SDA); PIN_ON(LCD_NOKIA_1100_SCLK); lcd_nokia1100_write(data); PIN_OFF(LCD_NOKIA_1100_CS); }
/** Main program entry point. This routine configures the hardware required by the application, then * enters a loop to run the application tasks in sequence. */ int main(void) { SetupHardware(); for (;;) { HID_Task(); PIN_ON(7); USB_USBTask(); PIN_OFF(7); } }
unsigned char One_Wire_Read_Bit (GPIO_TypeDef * GPIOx, u16 PINx) { unsigned char tmp; PIN_OUT_PP(GPIOx, PINx); PIN_OFF(GPIOx, PINx); delay_us(Time_Hold_Down); PIN_IN(GPIOx, PINx); delay_us(Time_Pulse_Delay_Low); if ((PIN_SYG(GPIOx, PINx))!=0) tmp = 1; else tmp = 0; delay_us(Time_Pulse_Delay_High); return tmp; }
enum armv2_status interrupt(struct armv2 *cpu, uint32_t hw_id, uint32_t code) { if(NULL == cpu || !CPU_INITIALISED(cpu)) { return ARMV2STATUS_INVALID_ARGS; } //TODO: some kind of interrupt queue, for now drop interrupts that happen while we're doing this if(PIN_OFF(cpu,I) && FLAG_CLEAR(cpu,I)) { cpu->hardware_manager.last_interrupt_id = hw_id; cpu->hardware_manager.last_interrupt_code = code; SETPIN(cpu,I); } return ARMV2STATUS_OK; }
void lcd_nokia1100_write(uint8_t data) { uint8_t bit_number; for (bit_number = 8; bit_number-- > 0;) { PIN_OFF(LCD_NOKIA_1100_SCLK); if (data & 0x80) { PIN_ON(LCD_NOKIA_1100_SDA); } else { PIN_OFF(LCD_NOKIA_1100_SDA); } PIN_ON(LCD_NOKIA_1100_SCLK); data <<= 1; } }
unsigned int One_Wire_Reset(GPIO_TypeDef * GPIOx, u16 PINx) { unsigned int tmp; PIN_IN(GPIOx, PINx); if ((PIN_SYG(GPIOx, PINx))==0) return One_Wire_Bus_Low_Error; PIN_OUT_PP(GPIOx, PINx); PIN_OFF(GPIOx, PINx); delay_us(Time_Reset_Low); PIN_ON(GPIOx, PINx); PIN_IN(GPIOx, PINx); delay_us(Time_Pulse_Delay_High); if ((PIN_SYG(GPIOx, PINx))==0) tmp=One_Wire_Success; else tmp=One_Wire_Error_No_Echo; delay_us(Time_After_Reset); return tmp; }
void One_Wire_Write_Bit (unsigned char Bit,GPIO_TypeDef * GPIOx, u16 PINx) { PIN_OUT_PP(GPIOx, PINx); PIN_OFF(GPIOx, PINx); if (Bit==0) { delay_us(Time_Pulse_Delay_High); PIN_ON(GPIOx, PINx); delay_us(Time_Pulse_Delay_Low); } else { delay_us(Time_Pulse_Delay_Low); PIN_ON(GPIOx, PINx); delay_us(Time_Pulse_Delay_High); } PIN_IN(GPIOx, PINx); }
void main(void) { gpio_init(); lcd_nokia1100_init(); lcd_nokia1100_set_position(7, 0); lcd_nokia1100_print_string((uint8_t *) "ZiBlog.ru @ 2014"); lcd_nokia1100_set_position(0, 0); lcd_nokia1100_print_string((uint8_t *) "STM32F4Discovery"); lcd_nokia1100_set_position(4, 1); lcd_nokia1100_print_string((uint8_t *) "LCD Nokia 1100"); while (1) { if (PIN_SIGNAL(PIN_BUTTON)) { PIN_ON(PIN_LED); } else { PIN_OFF(PIN_LED); } } }
void motor_brake() { MOTOR_DISABLE(); PIN_OFF(PORTD, PIN_M_1A); PIN_OFF(PORTD, PIN_M_2A); }
void motor_stop() { PIN_OFF(PORTD, PIN_M_1A); PIN_OFF(PORTD, PIN_M_2A); }
char Get_key(void) { char key = 0; uint16_t button_port = 0; PIN_ON(OUT_1); //in open-drain mode = Hi-Z ! PIN_ON(OUT_2); // for(char i=0; i<2; i++) // { if(key==0) { PIN_ON(OUT_1); //Hi-Z PIN_OFF(OUT_2); //open-drain button_port = GPIOC->IDR; button_port =~button_port; button_port &= (uint16_t)0x003F; //select key bits switch(button_port) { case 1: key = 1; break; case 2: key = 2; break; case 4: key = 3; break; case 8: key = 4; break; case 16: key = 5; break; case 32: key = 6; break; default : key = 0; } } if(key==0) { PIN_ON(OUT_2); PIN_OFF(OUT_1); button_port = GPIOC->IDR; button_port =~button_port; button_port &= (uint16_t)0x003F; //select key bits switch(button_port) { case 1: key = 7; break; case 2: key = 8; break; case 4: key = 9; // break; case 8: key = 10; // break; case 16: key = 11; // break; case 32: key = 12; // break; default : key = 0; } } //} PIN_ON(OUT_1); //in open-drain mode = Hi-Z ! PIN_ON(OUT_2); if(key) { //SPI2->DR = key; //To DM //send_to_usart(key); //debug OutData return key; }; return 0; }
void get_buttons_state(){ switch(get_keyboard_state()){ case BTN_STATE_ENTER: if(save_pressed_buton(BTN_STATE_ENTER, true)) {return;}//если кнопка все еще нажата - выходим switch(regim){ case DISPLAY_REGIM_DEFAULT: case DISPLAY_REGIM_WATERING: case DISPLAY_REGIM_MANUAL_WATERING: case DISPLAY_REGIM_NO_WATER: init_bright_contrast(); bright_off_count = 0; return; case DISPLAY_REGIM_MENU: btn_enter_pressed_in_menu(); break; case DISPLAY_REGIM_SET_TIME_DATE: btn_enter_pressed_in_set_date_time(); break; case DISPLAY_REGIM_SET_WATERING_TIME: btn_enter_pressed_in_set_watering_time(); break; case DISPLAY_REGIM_SET_WAERING_DUR: btn_enter_pressed_in_set_watering_duration(); break; case DISPLAY_REGIM_SET_HUMIDITY: btn_enter_pressed_in_set_humidity(); break; case DISPLAY_REGIM_SET_CHK_INTERVAL: btn_enter_pressed_in_set_chk_interval(); break; case DISPLAY_REGIM_SET_WATERING_REG: btn_enter_pressed_in_set_watering_reg(); break; case DISPLAY_REGIM_SET_LIGHT: btn_enter_pressed_in_set_light_time(); break; case DISPLAY_REGIM_SET_BRIGHT_CONTR: btn_enter_pressed_in_set_bright_contrast(); break; } break; case BTN_STATE_MENU: if(save_pressed_buton(BTN_STATE_MENU, false)) {return;}//если кнопка все еще нажата - выходим regim = DISPLAY_REGIM_MENU; lcd_set_state(LCD_ENABLE, CURSOR_DISABLE); init_menu(); break; case BTN_STATE_START: if(save_pressed_buton(BTN_STATE_START, false)) {return;} if(get_TIM_state(TIM6) && regim != DISPLAY_REGIM_NO_WATER){ PIN_ON(WATERING_RELAY); //запуск полива (вкл.реле) regim = DISPLAY_REGIM_MANUAL_WATERING; } break; case BTN_STATE_EXIT: if(save_pressed_buton(BTN_STATE_EXIT, true)) {return;} switch(regim){ case DISPLAY_REGIM_WATERING: case DISPLAY_REGIM_MANUAL_WATERING: case DISPLAY_REGIM_DEFAULT: case DISPLAY_REGIM_NO_WATER: break; case DISPLAY_REGIM_MENU: regim = DISPLAY_REGIM_DEFAULT; TIM_Cmd(TIM7, ENABLE); break; case DISPLAY_REGIM_SET_TIME_DATE: case DISPLAY_REGIM_SET_WATERING_TIME: case DISPLAY_REGIM_SET_WAERING_DUR: case DISPLAY_REGIM_SET_HUMIDITY: case DISPLAY_REGIM_SET_CHK_INTERVAL: case DISPLAY_REGIM_SET_WATERING_REG: case DISPLAY_REGIM_SET_LIGHT: case DISPLAY_REGIM_SET_BRIGHT_CONTR: lcd_set_state(LCD_ENABLE, CURSOR_DISABLE); regim = DISPLAY_REGIM_MENU; break; } break; case BTN_STATE_LEFT: move_by_menu_LR(BTN_STATE_LEFT); break; case BTN_STATE_RIGHT: move_by_menu_LR(BTN_STATE_RIGHT); break; case BTN_STATE_STOP: switch(regim){ case DISPLAY_REGIM_WATERING: case DISPLAY_REGIM_MANUAL_WATERING: case DISPLAY_REGIM_DEFAULT: case DISPLAY_REGIM_NO_WATER: if(save_pressed_buton(BTN_STATE_STOP, false)) {return;} PIN_OFF(WATERING_RELAY); //стоп полива (откл.реле) PIN_OFF(NO_WATER_LED); regim = DISPLAY_REGIM_DEFAULT; check_humidity_sensor(); //если влажность ниже заданной - полив запуститьс¤ не зависимо от времени суток! check_humidity_value(); TIM_Cmd(TIM7, ENABLE); init_bright_contrast(); bright_off_count = 0; break; case DISPLAY_REGIM_MENU: case DISPLAY_REGIM_SET_TIME_DATE: case DISPLAY_REGIM_SET_WATERING_TIME: case DISPLAY_REGIM_SET_WAERING_DUR: case DISPLAY_REGIM_SET_HUMIDITY: case DISPLAY_REGIM_SET_CHK_INTERVAL: case DISPLAY_REGIM_SET_WATERING_REG: case DISPLAY_REGIM_SET_LIGHT: case DISPLAY_REGIM_SET_BRIGHT_CONTR: break; } break; default: btn_pressed = BTN_STATE_RESET; break; } }