html5-img
1 / 14

lcd_demo code 説明

lcd_demo code 説明. module lcd_test(enable,rw,cs1,cs2,di,db,clk); output enable,rw,cs1,cs2,di; output [7:0]db; input clk; reg rw,cs1,cs2,di; reg [7:0]db; reg [2:0]state=0; reg [5:0]clry; //reg [6:0]shcount; reg [2:0]clrx; reg [7:0]img[0:7][0:255]; // 用來存放” F”,”P”,”G”,”A” 四個字的編碼

margie
Télécharger la présentation

lcd_demo code 説明

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. lcd_demo code説明

  2. module lcd_test(enable,rw,cs1,cs2,di,db,clk); output enable,rw,cs1,cs2,di; output [7:0]db; input clk; reg rw,cs1,cs2,di; reg [7:0]db; reg [2:0]state=0; reg [5:0]clry; //reg [6:0]shcount; reg [2:0]clrx; reg [7:0]img[0:7][0:255]; //用來存放”F”,”P”,”G”,”A”四個字的編碼 reg flag,cs; //Clks //原始clk經除頻後產生一新的enable clk,提供給lcd module使用 parameter PosScan=11; //0 for pre-sim, 12 for real run reg [PosScan+3:0] Clks; always @(posedge clk) Clks=Clks+1; assign enable=Clks[PosScan];

  3. //state parameter FcnSet=0; parameter Xaddr=1; parameter Yaddr=2; parameter WriteData=3; parameter Scan=4; always @(posedge enable) //must use posedge edge begin //先將”F”,”P”,”G”,”A”四個字的編碼放入2維陣列img中 img[0][0]=8‘b11111111;//F img[0][1]=8'b00010001; img[0][2]=8'b00010001; img[0][3]=8'b00010001; img[0][4]=8'b00010001; img[0][5]=8'b00010001; img[0][6]=8'b00000001; img[0][7]=8'b00000000;

  4. img[0][8]=8'b11111111;//P img[0][9]=8'b00010001; img[0][10]=8'b00010001; img[0][11]=8'b00010001; img[0][12]=8'b00010001; img[0][13]=8'b00010001; img[0][14]=8'b00001110; img[0][15]=8'b00000000; img[0][16]=8'b00111110;//G img[0][17]=8'b01000001; img[0][18]=8'b10000001; img[0][19]=8'b10110001; img[0][20]=8'b10010001; img[0][21]=8'b10010001; img[0][22]=8'b01010001; img[0][23]=8'b00110110; img[0][25]=8'b11111000;//A img[0][26]=8'b00010100; img[0][27]=8'b00010010; img[0][28]=8'b00010001; img[0][29]=8'b00010001; img[0][30]=8'b00010010; img[0][31]=8'b00010100; img[0][32]=8'b11111000;

  5. case(state) //寫一FSM去控制 lcd module FcnSet:begin //啟動lcd顯示器 cs<=0; di<=0; rw<=0; cs1<=1; cs2<=1; db<=8'b00_111111; state<=Xaddr; end Xaddr:begin //設定X軸位址 di<=0; db<={5'b10111,clrx};//x address state<=Yaddr; end Yaddr:begin //設定Y軸位址 db<={2'b01,clry}; //y address state<=WriteData; end

  6. WriteData:begin //將資料寫入所要顯示的位置 di<=1; db<=8'd0; state<=Xaddr; if(clrx==7 && clry==63 && flag==0) //寫完一邊 begin //LCD(64*8byte)後 state<=Scan; //換寫另一邊的LCD end if(flag) begin if(clrx==7 && clry==63) begin cs<=~cs; state<=Scan; end if(cs1) //cs1=1將資料寫到左邊LCD(64*8byte) db<=img[clrx][clry]; else //cs2=1將資料寫到右邊LCD(64*8byte) db<=img[clrx][clry+64]; di<=1; end

  7. clry<=clry+1; if(clry==63) //寫到第63行時換寫下一列 begin clrx<=clrx+1; end end Scan:begin //切換掃描左邊LCD or 右邊LCD case(cs) 0:begin cs1<=1; cs2<=0; end 1:begin cs1<=0; cs2<=1; end endcase di<=0; flag<=1; state<=Xaddr; end endcase end endmodule

  8. LCD module spec.

  9. LCD module spec.

  10. THE END

More Related