/** * A routine that very slowly fills the screen with a color */ void paint(unsigned int color) { int i,j; LCD_SetWindow(0,0,239,400); for(i = 0; i < 400; i++) { for(j = 0; j < 240; j++) { LCD_Write_Data(color); } } }
/* Func: 写入字符串 */ void LCD_Write_Str(unsigned char x, unsigned char y, unsigned char *str){ if(y == 0){ LCD_Write_Com(0x80 + x); } else{ LCD_Write_Com(0xC0 + x); } while(*str){ LCD_Write_Data(*str); str++; } }
/*------------------------------------------------ 写入字符函数 ------------------------------------------------*/ void LCD_Write_Char(unsigned char x,unsigned char y,unsigned char Data) { if (y == 0) { LCD_Write_Com(0x80 + x); } else { LCD_Write_Com(0xC0 + x); } LCD_Write_Data( Data); }
/*------------------------------------------------ 写入字符串函数 ------------------------------------------------*/ void LCD_Write_String(unsigned char x,unsigned char y,unsigned char *s) { if (y == 0) { LCD_Write_Com(0x80 + x); //表示第一行 } else { LCD_Write_Com(0xC0 + x); //表示第二行 } while (*s) { LCD_Write_Data( *s); s ++; } }
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; } }
/** * A simple cog for painting the screen */ void LCD_Run(void) { FILE *fp; uint8_t buffer[500]; uint16_t x, y, i, j; int dataOffset; int size; int counter = 0; LCD_Init(); // Initialize the interface to the SD card sd_mount(SD_DO, SD_SCK, SD_DI, SD_SS); while(1) { // paint(0xF800); // pause(100); // paint(0x07E0); // pause(100); // paint(0x001F); // pause(100); // Open the first image if(counter == 0) { fp = fopen("1.bmp", "r"); counter++; } else { fp = fopen("2.bmp", "r"); counter = 0; } // Read in the header fread(buffer, 1, 54, fp); // Get the size of the image // 16 bit numbers, do some bit shifting x = buffer[18] + (buffer[19] << 8); y = buffer[22] + (buffer[23] << 8); //size = buffer[2] | (buffer[3] << 8) | (buffer[4] << 16) | (buffer[5] << 24); dataOffset = buffer[10] | (buffer[11] << 8) | (buffer[12] << 16) | (buffer[13] << 24); // Seek the file pointer to the start of the pixel data fseek(fp, dataOffset, SEEK_SET); LCD_SetWindow(0,0,239,400); for(i = 0; i < y; i++) { // Read a line in fread(buffer, 1, x * 2, fp); for(j = 0; j < x * 2; j += 2) { // Write the pixel data out to the display // Note that the pixel data is the Red, Green, Blue data in the 565 format, ie: // // Bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // Use B1 B2 B3 B4 B5 G0 G1 G2 G3 G4 G5 R1 R2 R3 R4 R5 // // Notice that we only have 5 bits of Blue and Red? The human eye is more sensitive // to the color green, so to make the RGB fit into 16 bits it is given priority LCD_Write_Data((buffer[j]) + (buffer[j+1] << 8)); } } // Close and prepare for the next file fclose(fp); } }