void Config_LCD(void){ //Config_Contrast_PWM(); //not needed for OLED, since no contrast pin //LCD_Init(); LCD_Init(); LCD_CursorOff(); //Build symbol in LCD's CGRAM to be used later on LCD_build(0, framelement); //build '||' symbol at location 0, used to draw frame LCD_build(1, PILOGO); //build Polltech LOGO at location 1 LCD_build(2,DegreeSym); }
int main(void) { DDRB = 1 << 6 | 1 << 0; PORTB = 0xBE; DDRD = 0xFF; DDRC = 0x03; //set and turn on system timer TimerSet(50); TimerOn(); LCD_init();//initialize lcd display for use //build custom characters for use throughout program LCD_build(0,angleLcdPattern); LCD_build(1,sunLcdPattern); LCD_build(2,moonLcdPattern); ADC_init();//initialize analog to digital converter PWM_on();//turn on PWM and servo control //Init SM states LcdDisplay_State = LcdInit; HumanDetect_State = InitDetection; LightSeek_State = LightSeekInit; ServoControl_State = ServoInit; //main loop while(1) { pirSensor = GetBit(PINB,1); //get reading from pir sensor HumanDetect_TickFct(); LightSeek_TickFct(); ServoControl_TickFct(); LcdDisplay_TickFct(); while(!TimerFlag); TimerFlag = 0; } }
void LCD_BuildCustomCharacters() { unsigned char pattern1[8] ={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f}; unsigned char pattern2[8] ={0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x1f}; unsigned char pattern3[8] ={0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x01f, 0x1f}; unsigned char pattern4[8] ={0x0, 0x0, 0x0, 0x0, 0x0, 0x1f, 0x1f, 0x1f}; unsigned char pattern5[8] ={0x0, 0x0, 0x0, 0x0, 0x1f, 0x1f, 0x1f, 0x1f}; unsigned char pattern6[8] ={0x0, 0x0, 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}; unsigned char pattern7[8] ={0x0, 0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}; unsigned char pattern8[8] ={0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f}; LCD_build(0,pattern1); LCD_build(1,pattern2); LCD_build(2,pattern3); LCD_build(3,pattern4); LCD_build(4,pattern5); LCD_build(5,pattern6); LCD_build(6,pattern7); LCD_build(7,pattern8); }
int main(void) { // PORT config DDRC = 0xFF; PORTC = 0x00; //1111 1111 : 0000 0000 //DDRB = 0xFF; PORTB = 0x00; //1111 1111 : 0000 0000 DDRB = 0x03; PORTB = 0x00; DDRA = 0xFD; PORTA = 0x02; //1111 1101 : 0000 0010 DDRD = 0x0a; PORTD = 0x05; //scheduler setup static task motionSensorPoll, lcdDisplay, uoutTask, RT_Task, M_Task, hvacTask, sensorTimeoutTask; task *tasks[] = { &lcdDisplay, &motionSensorPoll, &uoutTask, &RT_Task, &M_Task, &hvacTask, &sensorTimeoutTask }; unsigned short numTasks = sizeof(tasks)/sizeof(task*); //USART task uoutTask.period = 50; uoutTask.TickFn = &uoutTick; //Remote timeout task RT_Task.period = 1000; RT_Task.TickFn = &remoteTimeoutTask; //Menu task M_Task.period = 100; M_Task.TickFn = &menuTask; //LCD display task lcdDisplay.period = 100; lcdDisplay.TickFn = &lcdDisplayTick; //Motion sensor polling task motionSensorPoll.period = 100; motionSensorPoll.TickFn = &motionSensorTick; //HVAC hvacTask.period = 500; hvacTask.TickFn = &hvacTick; // sensor timeout sensorTimeoutTask.period = 500; sensorTimeoutTask.TickFn = &sensorTimeoutTick; // Init radio spiInitMaster(); nrfMaster(); enableINT0(); // Init USART uoutInit(0); delay_ms(20); uoutSend("\n\r\n\r\n\r"); uoutSend(" Welcome to thermostat!\n\r"); uoutSend("==========================\n\r"); unsigned short gcd = tasksInit(tasks, numTasks); // Timer TimerSet(gcd); TimerOn(); //custom character for lcd unsigned char personPattern[8] = {0x04, 0x0A, 0x04, 0x1f, 0x04, 0x04, 0x0A, 0x11}; unsigned char fanOnPattern[8] = {0x00,0x06,0x1A,0x15,0x0B,0x0C,0x00,0x1F}; unsigned char fanAutoPattern[8] = {0x00,0x06,0x1A,0x15,0x0B,0x0C,0x00,0x00}; unsigned char onPattern[8] = {0x10, 0x12, 0x16, 0x1C, 0x18, 0x10, 0x10, 0x10}; unsigned char offPattern[8] = {0x10, 0x10, 0x10, 0x18, 0x1C, 0x16, 0x12, 0x10}; LCD_build(0,personPattern); LCD_build(1,fanOnPattern); LCD_build(2,fanAutoPattern); LCD_build(3,onPattern); LCD_build(4,offPattern); while(1) { sensor = GetBit(PINA,1); tasksTick(tasks, numTasks); while(!TimerFlag); // Wait for a GCD period TimerFlag = 0; } return 0; }