void LCM_set_view(U8 view_type, U16 x_start, U16 y_start, U16 x_size, U16 y_size) { data U8 x_end,y_end,mirrored_y_start,mirrored_y_end; data U8 tc_Dir; LCD_Nand2DataMode(); x_end = x_start + x_size - 1; y_end = y_start + y_size - 1; switch(view_type) { case 0: // HZK mirrored_y_start = y_start; mirrored_y_end = y_end; y_start=x_start; y_end=x_end; x_start = mirrored_y_start; x_end= mirrored_y_end; tc_Dir=0x90; break; case 1: // ICON tc_Dir=0xB0; break; case 2: // JPG tc_Dir=0xB0; break; case 3: // BMP mirrored_y_start = TFT_V_Size-1-y_end; mirrored_y_end = TFT_V_Size-1-y_start; y_start=mirrored_y_start; y_end=mirrored_y_end; tc_Dir=0xF0; break; } //Set Start X.Y address LCD_Write_Command(0x2A); // set X address LCD_Write_OneWord(x_start); LCD_Write_OneWord(x_end); LCD_Write_Command(0x2B); // set Y address LCD_Write_OneWord(y_start); LCD_Write_OneWord(y_end); //SetScanDirection LCD_Write_Command(0x36); LCD_Write_OneData(tc_Dir); LCD_Write_Command(0x2C);//Memory Write //Switch back to NAND I/F LCD_Data2NandMode(); }
int main(void) { //uint8_t Rx1_Buffer[BUFFER_SIZE1]; volatile uint16_t NumDataRead = 0; volatile uint16_t symbol; uint8_t command_buffer[10]= {0xe2,0xeb,0x81,120,0xc6,0xaf,0x88,0xb0,0x00,0x10}; uint32_t xtal_value; /* 0: 0xe2 - 11100010 - System Reset 1: 0xeb - 11101011 - Set LCD BIAS ratio [b1:b0] 2: 0x81 - 10000001 - Set VBIAS potentiometer 3: 0x50 - 01010000 - VBIAS potentiometer value 4: 0xc6 - 11000110 - Set LCD Mapping Control [b2:b1] 5: 0xaf - 10101111 - Set display ENABLE [b0] 6: 0x89 - 10001001 - Set RAM adress Control [b2:b0] 7: 0xb0 - 10110000 - Set Page Adress [b3:b0] 8: 0x00 - 00000000 - Set Column Adress LSB [b3:b0] 9: 0x10 - 00010000 - Set Column Adress MSB [b3:b0] */ uint32_t decimal[8]; //uint8_t string0[]="Display Works Fine"; //uint8_t tune.tune_freq_vis[]="14000000"; /*Start Frequency*/ //uint8_t string2[]="FREQUENCY"; //uint8_t string3[]="HAM RADIO BAND"; uint8_t string4[]="20m USB 2800Hz x100";/*BAND MODE FILTER GAIN*/ //uint8_t string5[]="MODE SSB USB"; //uint8_t string6[]="GAIN 1000"; uint8_t string7[]="PRE:Off ATT:20 AGC:S"; uint8_t data_buffer[132]; uint8_t data_buffer1[132]; uint8_t data_buffer2[132]; uint8_t data_buffer3[132]; uint8_t si570_buf[11]; uint32_t bit_order; uint8_t current_pointer; uint8_t k, n, sp, lzs_flag, symb_width, enc1_pulse_ccw, enc1_pulse_cw,enc2_pulse_ccw, enc2_pulse_cw, show_it; uint8_t option_select, sub_option_select; uint8_t n1; uint8_t hs_div_code; uint32_t i,j/*,noise_filter_button*/; uint8_t display_menu; uint8_t offcet_x; extern menu_struct_t menu[MAX_MENU_QTY]; extern band_struct_t band_menu[MAX_BAND_QTY]; extern mode_struct_t mode_menu[MAX_MODE_QTY]; extern filter_struct_t filter_menu[MAX_FILTER_QTY]; extern gain_struct_t gain_menu; extern tune_struct_t tune; RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 100); /* SysTick end of count event each 10ms */ //if (FLASH_OB_GetRDP()!=SET) //{ // FLASH_OB_Unlock(); /*enable the FLASH option control register access*/ // FLASH_OB_RDPConfig(OB_RDP_Level_1); /*SET RDP=1*/ // FLASH_OB_Launch(); /*launch the Option Bytes programming process*/ // FLASH_OB_Lock(); /*disable the FLASH option control register*/ //} /* Initialize LEDs and LCD available on STM324xG-EVAL board *****************/ STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); /* Initialize user button STM324xG-EVAL board *****************/ STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO); STM_EVAL_ControlInit(CODEC_RESET); BOARD_GPIO_Init(); /*encoder input init*/ /* Turn on LEDs available on STM324xG-EVAL **********************************/ STM_EVAL_LEDOff(LED3); STM_EVAL_LEDOff(LED4); STM_EVAL_LEDOff(LED5); STM_EVAL_LEDOff(LED6); STM_EVAL_ControlOn(CODEC_RESET); Delay (300); STM_EVAL_ControlOff(CODEC_RESET); xtal_value=(uint32_t)114197425;/*0x6cfd9c8*/ freq_code_old=0; NumDataRead = 1; /* Initialize the I2C EEPROM driver ----------------------------------------*/ sEE_Init(); /* Initialize the CODEC driver*/ EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S); EVAL_AUDIO_Init(OUTPUT_DEVICE_HEADPHONE, 255, I2S_AudioFreq_48k); EVAL_AUDIO_Play(sound, 96); /*Continuous Beep from codec*/ Codec_WriteRegister(0x1E, 0xC0); Delay (100); LCD_Write_Command(0x70, command_buffer, 1); Delay (10); LCD_Write_Command(0x70, (command_buffer+1), 5); Delay (10); n=0xA1;/*100 Hz frame rate*/ LCD_Write_Command(0x70, &n, 1); bit_order=0x989680; /*1e+7 decimal*/ for (j=0; j<8; j++) /*filling array for decimal to binary conversion*/ { decimal[j]=bit_order; bit_order=bit_order/10; } /*Clear display*/ symbol=0x00; for (j=0; j<8; j++) { for (i=0; i<131; i++) { data_buffer[i]=symbol; } LCD_Write_Command(0x70, (command_buffer+6), 4); Delay (10); LCD_Write_Data(0x70, data_buffer, (uint32_t)132); command_buffer[7]++; Delay (10); } si570_buf[6]=0x10;/*freeze DCO reg 137*/ si570_buf[7]=0x00;/*unfreeze DCO reg 137*/ si570_buf[8]=0x40;/*status new dco reg 135*/ si570_buf[9]=0x20;/*freeze M bit reg 135*/ si570_buf[10]=0x00;/*unfreeze M bit reg 135*/ // command_buffer[7]=0xb3; // LCD_Write_Command(0x70, (command_buffer+6), 4); freq2=0; i=5; j=0; k=0; sp=0; display_menu=0; show_it=1; /*initial display*/ display_menu=1; current_menu=0; old_value=new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK; while (1) { new_value=((uint32_t)GPIO_ReadInputData(GPIOB))&ENCODERS_MASK; if (new_value!=old_value) { current_pointer=1; enc1_old_value=old_value&ENCODER1_MASK; enc2_old_value=old_value&ENCODER2_MASK; enc1_new_value=new_value&ENCODER1_MASK; enc2_new_value=new_value&ENCODER2_MASK; if (enc2_new_value!=enc2_old_value) { current_pointer=0; if ((enc2_old_value&ENCODER2_A_MASK)!=((enc2_new_value<<1)&ENCODER2_A_MASK))/*==ENCODER2_MASK*/ { STM_EVAL_LEDToggle(LED3); enc2_pulse_ccw=0; enc2_pulse_cw++; } else { STM_EVAL_LEDToggle(LED6); enc2_pulse_cw=0; enc2_pulse_ccw++; } //old_value=new_value; if (enc2_pulse_cw==4) /*increment*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/ { menu[current_menu].menu_current_state++; if(menu[current_menu].menu_current_state>menu[current_menu].menu_states_qty-1) /*control if submenu<MAX_SUBMENU*/ { menu[current_menu].menu_current_state=0; } /*apply handler with action parameter*/ } else /*change menu*/ { current_menu++; if (current_menu>MAX_MENU_QTY-1) /*control if menu<MAX_MENU*/ { current_menu=0; } } enc2_pulse_cw=0; enc2_pulse_ccw=0; display_menu=1; if (current_menu==0) show_it=1; } else { if (enc2_pulse_ccw==4) /*decrement*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) /*if user button not pressed - > change sub menu*/ { menu[current_menu].menu_current_state--; if (menu[current_menu].menu_current_state<0) { menu[current_menu].menu_current_state=menu[current_menu].menu_states_qty-1; } /*apply handler with action parameter*/ } else /*change menu*/ { current_menu--;/*control if menu<MAX_MENU*/ if (current_menu<0) { current_menu=MAX_MENU_QTY-1; } } enc2_pulse_cw=0; enc2_pulse_ccw=0; display_menu=1; if (current_menu==0) show_it=1; } } } if (current_pointer==1) { if ((enc1_old_value&ENCODER1_A_MASK)!=((enc1_new_value<<1)&ENCODER1_A_MASK))/*==ENCODER1_MASK*/ { STM_EVAL_LEDToggle(LED5); enc1_pulse_ccw=0; enc1_pulse_cw++; } else { STM_EVAL_LEDToggle(LED4); enc1_pulse_cw=0; enc1_pulse_ccw++; } old_value=new_value; /*--------------------------------------------------*/ if (enc1_pulse_cw==4) /*increment*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) { for (j=1; j<8-i; j++) { tune.tune_freq_vis[i+j]=0x30; } enc1_pulse_cw=0; enc1_pulse_ccw=0; if ((tune.tune_freq_vis[i]&0x0f)==0x09) { tune.tune_freq_vis[i]=0; j=1; while ((tune.tune_freq_vis[i-j]&0x0f)==0x09) { tune.tune_freq_vis[i-j]=0; j++; } tune.tune_freq_vis[i-j]++; } else { tune.tune_freq_vis[i]++; } show_it=1; } else { enc1_pulse_cw=0; enc1_pulse_ccw=0; if (i==7) { i=0; } else { i++; } show_it=1; } } /*--------------------------------------------------*/ else { if (enc1_pulse_ccw==4) /*decrement*/ { if (STM_EVAL_PBGetState(BUTTON_USER)==0) { for (j=1; j<8-i; j++) { tune.tune_freq_vis[i+j]=0x30; } enc1_pulse_cw=0; enc1_pulse_ccw=0; if ((tune.tune_freq_vis[i]&0x0f)==0x00) { tune.tune_freq_vis[i]=9; j=1; while ((tune.tune_freq_vis[i-j]&0x0f)==0x00) { tune.tune_freq_vis[i-j]=9; j++; } tune.tune_freq_vis[i-j]--; } else { tune.tune_freq_vis[i]--; } } else { enc1_pulse_cw=0; enc1_pulse_ccw=0; if (i==0) { i=7; } else { i--; } show_it=1; } } show_it=1; } } if (display_menu==1) /*build menu buffer*/ { display_menu=0; pp1=menu[current_menu].pFunc(MODIFY); for (j=0; j<MAX_MENU_QTY; j++) { k=0; offcet_x=menu[j].menu_x_pos; pp1=menu[j].pFunc(DISPLAY); if (j==current_menu) { data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; k++; while ((*pp1)!=0) { for (jj=0; jj<5; jj++) { symbol=symboltable[(*pp1)-0x20][jj]; data_buffer2[k+offcet_x]=~(symbol<<2);/*Fill Upper buffer*/ data_buffer3[k+offcet_x]=~((symbol>>6)|0xF8); k++; } data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; k++; pp1++; } data_buffer2[k+offcet_x]=0xFF; data_buffer3[k+offcet_x]=0x07; } else { data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; k++; while ((*pp1)!=0) { for (jj=0; jj<5; jj++) { symbol=symboltable[(*pp1)-0x20][jj]; data_buffer2[k+offcet_x]=(uint8_t)symbol<<2;/*Fill Upper buffer*/ data_buffer3[k+offcet_x]=(uint8_t)symbol>>6; k++; } data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; k++; pp1++; } data_buffer2[k+offcet_x]=0x00; data_buffer3[k+offcet_x]=0x00; } }
/** * Initialize the LCD interface. The LCD uses negative logic, so we need * to set various pins high. * * TODO document the config options better and optimize */ void LCD_Init(void) { // Set pins as output set_direction(LCD_RST, 1); set_direction(LCD_CS, 1); set_direction(LCD_RS, 1); set_direction(LCD_WR, 1); set_direction(LCD_RD, 1); // Reset the display set_output(LCD_RST, 1); pause(5); set_output(LCD_RST, 0); pause(10); set_output(LCD_RST, 1); // Set the pins high set_output(LCD_CS, 1); set_output(LCD_RS, 1); set_output(LCD_WR, 1); set_output(LCD_RD, 1); set_directions(7, 0, 0xFF); LCD_SyncTransfer(); // Soft reset LCD_Write(LCD_SOFTWARE_RESET, 0x0001); pause(1); LCD_Write(LCD_SOFTWARE_RESET, 0x0000); LCD_Write(LCD_BASE_IMAGE_NB_LINE, 0x6200); LCD_Write(LCD_DISPLAY_CONTROL_2, 0x0808); // Gamma correction LCD_Write(LCD_GAMMA_CONTROL_1, 0x0C00); LCD_Write(LCD_GAMMA_CONTROL_2, 0x5A0B); LCD_Write(LCD_GAMMA_CONTROL_3, 0x0906); LCD_Write(LCD_GAMMA_CONTROL_4, 0x1017); LCD_Write(LCD_GAMMA_CONTROL_5, 0x2300); LCD_Write(LCD_GAMMA_CONTROL_6, 0x1700); LCD_Write(LCD_GAMMA_CONTROL_7, 0x6309); LCD_Write(LCD_GAMMA_CONTROL_8, 0x0C09); LCD_Write(LCD_GAMMA_CONTROL_9, 0x100C); LCD_Write(LCD_GAMMA_CONTROL_10, 0x2232); /* LCD_Write(LCD_PANEL_IF_CONTROL_1, 0x0016); // Clocks per line, osc divisor LCD_Write(LCD_PANEL_IF_CONTROL_2, 0x0101); LCD_Write(LCD_PANEL_IF_CONTROL_3, 0x0000); LCD_Write(LCD_PANEL_IF_CONTROL_4, 0x0001); */ // Power control LCD_Write(LCD_POWER_CONTROL_1, 0x0330); //BT,AP LCD_Write(LCD_POWER_CONTROL_2, 0x0237); //DC0,DC1,VC LCD_Write(LCD_POWER_CONTROL_4, 0x0D00); //VDV LCD_Write(LCD_NVM_DATA_RW, 0x6100); //VCM LCD_Write(LCD_POWER_CONTROL_3, 0xC1B0); //VRH,VCMR,PSON,PON pause(50); // LCD_Write(LCD_DRIVER_OUTPUT_CONTROL, 0x0100); LCD_Write(LCD_LCD_DRIVE_WAVE_CONTROL, 0x0100); // B[8] Line inversion LCD_Write(LCD_ENTRY_MODE, 0x5030); // B[3] Address counter goes horizontal // B[5:4] Horizontal decrement, vertical increment // B[7] Orgin not moved // B[12] Write data in BGR mode // B[14] 16bpp // B[15] Two transfers per 16 bits // LCD_Write(LCD_EXT_DISPLAY_IF_CONTROL_1, 0x0001); // B[0] 16 bit color // B[5:4] Internal clock // B[8] RAM can be accessed while doing display // B[14:12]RAM write cycle is 1 frame LCD_Write(LCD_FRAME_MARKER_CONTROL, 0x8000); // LCD_Write(LCD_EXT_DISPLAY_IF_CONTROL_2, 0x0000); LCD_Write(LCD_WIN_H_RAM_ADRR_START, 0x0000); LCD_Write(LCD_WIN_H_RAM_ADRR_END, 0x00EF); LCD_Write(LCD_WIN_V_RAM_ADRR_START, 0x0000); LCD_Write(LCD_WIN_V_RAM_ADRR_END, 0x018F); //432=01AF,400=018F LCD_Write(0x0500, 0x0000); LCD_Write(0x0501, 0x0000); LCD_Write(0x0502, 0x005F); LCD_Write(LCD_BASE_IMAGE_DISPLAY_CTRL, 0x0001); LCD_Write(LCD_BASE_IMAGE_V_SCROLL_CTRL, 0x0000); pause(50); LCD_Write(LCD_DISPLAY_CONTROL_1, 0x0100); //BASEE pause(50); LCD_Write(LCD_RAM_ADRR_SET_H, 0x0000); LCD_Write(LCD_RAM_ADRR_SET_V, 0x0000); LCD_Write_Command(LCD_RAM_RW); }