FFT算法在單片機中的使用&&LCD12864驅動
void initw(); //初始化旋轉因子
void bitReverse(); //比特反轉
void FFT();
complex x[N];
uchar vis[N];
void delayms(uint ms)
{
uint i,j;
for(i=0;i for(j=0;j<3;j++); } } //此處定義字符串 //寫數(shù)據(jù) void WriteDataLCM(unsigned char WDLCM) //寫數(shù)據(jù)函數(shù) { // ReadStatusLCM(); //檢測忙 delayms(1); PORTA|=RS; //RS=1 delayms(1); PORTA&=~RW; //RW=0 delayms(1); PORTA|=EN; //EN=1 delayms(1); PORTB=WDLCM; //輸出數(shù)據(jù) delayms(1); PORTA&=~EN; //EN=0 delayms(1); } //寫指令 void WriteCommandLCM(unsigned char WCLCM) //寫命令函數(shù) { // ReadStatusLCM(); //根據(jù)需要檢測忙 delayms(1); PORTA&=~RS; //RS=0 delayms(1); PORTA&=~RW; //RW=0 delayms(1); PORTA|=EN; //EN=1 delayms(1); PORTB=WCLCM; //輸出指令 delayms(1); PORTA&=~EN; //EN=0 delayms(1); } //讀狀態(tài):檢測忙 void ReadStatusLCM() //讀狀態(tài)函數(shù) { uchar temp; uchar flag = 1; while(flag==1) { PORTB=0xff; delayms(1); DDRB=0x00; //端口B改為輸入 delayms(1); PORTA&=~RS; //RS=0 delayms(1); PORTA|=RW; //RW=1 delayms(1); PORTA|=EN; //EN=1 delayms(10); temp = PINB; //讀端口B delayms(10); DDRB=0xff; //端口B改為 delayms(10); PORTA&=~EN; //EN=0 delayms(1); if(temp>>7==0) flag = 0; } } uchar read_data() //讀數(shù)據(jù)函數(shù) { uchar lcd_data; PORTB=0xff; DDRB=0x00; PORTA|=RW; PORTA|=RS; delayms(10); PORTA|=EN; delayms(10); lcd_data=PINB; delayms(10); PORTA&=~EN; DDRB=0xff; return(lcd_data) ; } void point(uchar x,uchar y) //打點函數(shù),最重要的函數(shù),GUI的基礎 { uchar x_Dyte,x_byte; uchar y_Dyte,y_byte; uchar GDRAM_hbit,GDRAM_lbit; WriteCommandLCM(0x36); x_Dyte=x/16; x_byte=x&0x0f; y_Dyte=y/32; y_byte=y&0x1f; WriteCommandLCM(0x80+y_byte); WriteCommandLCM(0x80+x_Dyte+8*y_Dyte); read_data(); GDRAM_hbit=read_data(); GDRAM_lbit=read_data(); delayms(10); WriteCommandLCM(0x80+y_byte); WriteCommandLCM(0x80+x_Dyte+8*y_Dyte); delayms(10); if(x_byte<8) { WriteDataLCM(GDRAM_hbit|(0x01<<(7-x_byte))); WriteDataLCM(GDRAM_lbit); } else { WriteDataLCM(GDRAM_hbit); WriteDataLCM(GDRAM_lbit|(0x01<<(15-x_byte))); } WriteCommandLCM(0x30); } //LCM初始化 void LCMInit(void) { WriteCommandLCM(0x30); //三次顯示模式設置,不檢測忙信號 delayms(10); WriteCommandLCM(0x30); delayms(10); WriteCommandLCM(0x30); delayms(10); WriteCommandLCM(0x30); //顯示模式設置,開始要求每次檢測忙信號 WriteCommandLCM(0x08); //關閉顯示 WriteCommandLCM(0x01); //顯示清屏 WriteCommandLCM(0x06); //顯示光標移動設置 WriteCommandLCM(0x0C); //顯示開及光標設置 }
評論