// initialize LCD pins and LCD controller void lcd_init(void) { // set direction of pins IO_OPF(C, 3); // CS/ pin IO_OP(E, 5); // DATA pin IO_OP(F, 4); // WR/ pin IO_OP(D, 2); // Backlight pin // set default values to pins CS1; WR1; DATA1; LCD_BCK0; // initialize timer 4 used to time WR/ signal BSET(CLK_PCKENR1, 4); // enable clock to TIM4 TIM4_CR1 = 0b00001100; // no auto-reload, one-pulse,URS-overflow, disable TIM4_IER = 0; // no interrupts TIM4_PSCR = 0; // prescaler = 1 TIM4_ARR = 24; // it will be about 600kHz for WR/ signal TIM4_CNTR = 0; // reset timer value // initialize HT1621B lcd_command(HT_BIAS_13 | (0b10 << HT_BIAS_SHIFT)); // BIAS 1/3, 4 COMs lcd_command(HT_RC_256K); // clock RC 256kHz lcd_command(HT_SYS_DIS); // OSC+BIAS off lcd_command(HT_WDT_DIS); // disable WDT lcd_command(HT_SYS_EN); // OSC on lcd_command(HT_LCD_ON); // BIAS on // initialize LCD task, will be used when sending following lcd_command-s build(LCD); activate(LCD, lcd_loop); sleep(LCD); // no work yet }
// initialize PPM pin and timer 3 void ppm_init(void) { IO_OP(D, 0); // PPM output pin, TIM3_CH2 // initialize timer3 used to generate PPM signal BSET(CLK_PCKENR1, 6); // enable master clock to TIM3 TIM3_CCMR2 = 0b01111000; // PWM2, OC2 preload, output mode TIM3_CCER1 = 0b00010000; // polarity active-high, OC2 enable TIM3_PSCR = PPM_PSC_SYNC; TIM3_IER = 1; // update interrupt enable TIM3_CR1 = 0b10000000; // auto-reload, URS-all, counter-disable ppm_set_channels(3); }