2012年12月7日 星期五

33 books written by D.A.Godse A.P.Godse



D.A.Godse A.P.Godse

33 books written by D.A.Godse A.P.Godse
  • Digital Logic Design
    (2009) | 641 pages
  • Microcontrollers
    (2009) | 354 pages
  • Microprocessors
    (2009) | 564 pages
  • Microprocessors And Applications
    (2009) | 884 pages
  • Logic Design
    (2009) | 542 pages
  • Switching Theory & Logic Design
    (2009) | 707 pages
  • Microprocessors And Interfacing
    (2009) | 606 pages
  • Digital Ic Applications
    (2009) | 744 pages
  • Computer Organization
    (2008) | 680 pages
  • Digital Techniques
    (2008) | 716 pages
  • Microprocessors & Microcontroller Systems
    (2008) | 644 pages
  • Microprocessor, Microcontroller & Applications
    (2008) | 486 pages
  • Advanced Microprocessors And Microcontroller
    (2008) | 899 pages
  • Microprocessors And Its Applications
    (2008) | 1018 pages
  • Microprocessor Techniques
    (2008) | 824 pages
  • Digital System Design
    (2008) | 664 pages
  • Fundmentals Of Programming
    (2008) | 455 pages
  • Computer Concepts And C Programming
    (2008) | 424 pages
  • Digital Design & Computer Organisation
    (2008) | 628 pages
  • Microprocessor - Iii
    (2008) | 236 pages
  • Computer Organization
    (2008) | 446 pages
  • Introduction To Microprocessor
    (2007) | 576 pages
  • C Programming And Data Structures
    (2007) | 516 pages
  • Microcontroller & Applications
    (2007) | 264 pages
  • Advanced Microprocessor
    (2007) | 532 pages
  • Microcontroller And Embedded Systems
    (2007) | 270 pages
  • Elements Of Microprocessors
    (2007) | 900 pages
  • Microprocessor And Assembly Language Programming
    (2007) | 432 pages
  • Computer Programming
    (2007) | 460 pages
  • Computer Architecture & Organisation
    (2007) | 440 pages
  • Digital Computer Fundamentals
    (2007) | 344 pages
  • Computer Organisation and Architecture
    (2006) | 364 pages
  • Digital Systems
    (2005) | 743 pages


2012年12月5日 星期三

LCD原理與控制


源自於 http://faculty.stut.edu.tw/~wjshieh/lcd.html
LCD原理與控制
一.種類:可分為
  1.文字型:已經有內建文字圖形(通常只有英文字母大小寫、阿拉伯數字、標點符號),
    只要輸入對應的字形碼(ASCII  code),LCD便會將該字的圖形顯示於LCD,可參考課
 本第三篇第三章。
  2.繪圖型:只能用繪圖的方式將資料顯示於LCD,所以必須先將要顯示文字的圖形依LCD所
    需的格式事先存起來,如一個16x15的中文字便需儲存30byte的資料,將此30byte的資
 料依序填入LCD即可顯示對應文字圖形,可參考課本第四篇第二章。
  3.文字繪圖兩用型:可依使用者需要切換成文字型或繪圖型。
    在此我們只討論如何控制文字型LCD

二.原理
下圖為目前市面上常見的文字型LCD基本的方塊圖,
其LCD接腳的功能為
1
Vss
接地(0 V)
2
Vdd
電源 (+5 V)
3
Vo
LCD亮度控制(0 V最亮)
4
RS
暫存器選擇:1 資料
0 指令
5
R/W
讀/寫選擇:1 從LCD讀取資料
           0 寫資料給LCD
6
E
致能LCD,負緣動作
7
D0
LCD 資料線
8
D1
9
D2
10
D3
11
D4
12
D5
13
D6
14
D7

LCD字型編碼表(此圖版權屬張義和,例說89S51-C語言,新文京開發出版社所有)

因為LCD本身並不會發亮,為了使夜間能看清楚LCD內容,某些LCD模組另外提供A、K做為背光用的電源接腳,有些廠商為了控制簡化,已將此兩接腳及相關電路接到LCD的電源腳,所以LCD只要1、2接上電源就LCD背光就會亮。
目前常見控制LCD的晶片最高可控制顯示80個字元,但實際LCD面板尺寸依價錢及使用者需求而有不同的規格,目前市面較常見的規格有16字x2行或20字x2行。
三.控制方法
8051可以透過LCD接腳D0~D7存取命令或資料,接腳RS、R/W依其排列組合可產生下列功能:
RS
R/W
功   能
0
0
寫命令到LCD
0
1
讀取忙碌旗號和位址計數器AC(記錄目前游標位址)內容
1
0
寫資料到DDRAM(要顯示的文字)或CGRAM(要造字的字形)
1
1
從DDRAM或CGRAM讀取資料
  在寫入狀態(R/W=0)時,當接腳E產生負緣訊號,LCD便將資料線D0~D7取入LCD處理,依照RS設定狀態,
  決定此資料為控制命令(RS=0)或是要顯示或造字的資料。
  在讀取狀態(R/W=1)時,當接腳E產生負緣訊號,LCD便依照RS設定狀態,將資料從 D0~D7送出來。
  
  PS:8051如何產生負緣訊號給LCD接腳E?
  
       SETB      E
       CLR       E    ;where E is the pin of 8051  which connect to LCD
  
  在多數應用的場合中,我們常直接將接腳R/W接地,使其一直處於寫入狀態,這樣8051可節省一隻接腳去控
  制它,但以後寫資料或命令給LCD時,需保留足夠的處理時間給LCD(因為無法判斷LCD是否已處理好,且用
  讀取LCD忙碌旗號來判斷是否處理完的程式並不會比較好寫),另外游標實際所在的位置也需處理好。
 


 若已知8051與LCD的接法如下圖所定義,將接腳R/W接地,使其處於寫入命令或資料的狀態,這樣在控制時,單晶片可節省

一支接腳,但須注意控制資料及命令寫入之後的延遲時間,寧可時間長一些,以避免LCD在未處裡完成前給予下一筆資料。

我們便可依上述說明及電路接法設計寫資料和命令給LCD的副程式。
  ;定義接腳名稱 
  LCDBUS  EQU    P0            ;LCD位置
  RS      EQU    P2.6
  ENABLE  EQU    P2.7
  ;-----  WRITE 資料 TO  LCD --------------
  WRDR:   SETB   RS           ;RS=1 => 寫資料到LCD
          SETB   ENABLE       ;E=1
          MOV    LCDBUS,A 
          MOV    R7,#5        ;等待約10us等8051輸出電壓穩定 
          DJNZ   R7,$   
          CLR    ENABLE        ;E=0  => 接腳E產生負緣訊號 
          MOV    R7,#25        ;等待約50us等LCD將資料處理完畢
          DJNZ   R7,$ 
          RET 
  
  ;-----  WRITE 命令 TO  LCD --------------
  WRIR:   CLR    RS            ;RS=0 => 寫命令到LCD
          SETB   ENABLE
          MOV    LCDBUS,A 
          MOV    R7,#5
          DJNZ   R7,$ 
          CLR    ENABLE 
          MOV    R7,#25
          DJNZ   R7,$ 
          RET 


  
下表為有關LCD的控制命令表:(詳細說明請參考課本)
    
命令
指令編碼

RS
R/W
DB7
DB6
DB5
DB4
DB3
DB2
DB1
DB0
1.清除顯示器
0
0
0
0
0
0
0
0
0
1
2.游標歸位
0
0
0
0
0
0
0
0
1
X
3.進入模式設定
0
0
0
0
0
0
0
1
I/D
S
4.顯示器ON/Off控制
0
0
0
0
0
0
1
D
C
B
5.顯示器或游標移動
0
0
0
0
0
1
S/C
R/L
X
X
6.功能設定
0
0
0
0
1
DL
N
F
X
X
7.CGRAM 位址設定
0
0
0
1
AC5
AC4
AC3
AC2
AC1
AC0
8.DDRAM 位址設定
0
0
1
AD6
AD5
AD4
AD3
AD2
AD1
AD0
 
 
1.清除顯示器

  功能:LCD畫面清除,LCD位址計數器AC=0,即游標移到左上角。 
  
  範例: 
         MOV     A,#1
         CALL    WRIR
  
  依照課本說明完成此命令需1.64ms,為安全起見,下達此命令後須等2ms以上,等LCD處理完此命令後,
  才能再給LCD下一命令或資料,否則在LCD尚未處理完之前給的任何命令或資料均屬無效。 


2.游標歸位

  功能:LCD畫面不變,LCD位址計數器AC=0,游標移到左上角。 
  
  範例: 
         MOV     A,#00000010B
         CALL    WRIR
  依照課本說明完成此命令需1.64ms,時間較長,可以用第8個命令取代,亦可達到相同效果,
  所花時間只要40us。 
  
         MOV     A,#10000000B   ;設定游標移至位址00的地方
         CALL    WRIR


3.進入模式設定 


6. 功能設定
   早期的CPU有4位元及8位元2種,這個命令主要是配合不同CPU介面設計,當設定CPU介面為4位元時,
   只有DB7~DB4有作用,以後要送8位元資料時,都要將資料拆成2筆4位元資料,再分2次給LCD。目前
   CPU都是8位元,LCD也幾乎都是2行的,所以標準命令如下


         MOV     A,#00111000B   ;設定LCD介面長度為8位元,2行,5x7字型
         CALL    WRIR
         
        (因為需先確定LCD與CPU間的介面形式,所以此命令必須最先執行)


7.CGRAM 位址設定
  此命令提供使用者自行造字之功能,若LCD字型編碼表上沒有想顯示的字,使用者可自行造字,最多可
  造8個字,此命令共保留6個位元,前3位元表示第n個字(n<=8), 後3位元代表該字的第幾行(共8行,最
  後一行要填0),每一行的資料只有5位元,前3位元沒用到可直接給0或省略不寫,結果相同。
  

         MOV     A,#01000000B   ;設定寫入字型資料, 從第一字的第一行開始
         CALL    WRIR


LCD造字範例(此圖版權屬張義和,例說89S51-C語言,新文京開發出版社所有)
範例程式(ASM)

以下練習所使用之實驗版,茲節錄控制電路如後。

注意事項:
1.笙泉的82G516執行速度較快,如果將其他8051系列的LCD控制程式移植到82G516上執行,須調整寫入後的延遲時間,
  否則可能會無法正常工作。
2.如果要在程式一開始就直接規劃LCD,建議先加一小段延遲程式,否則可能因LCD穩定時間較慢,單晶片在LCD還沒穩
  定前所做的規劃是沒有意義的,LCD當然不能正常工作。一般在使用ICE測試時,電源早已啟動,不會有這個問題,
  等實際燒錄作測試,需再按RESET才可正常工作時,通常是因為這個原因。
範例下載1(ASM),下載2(ASM)
範例下載(C)
在LCD上顯示時間(時分秒)
範例下載(ASM)
注意:為便於觀察,LCD上顯示時間比實際快10倍,請自行調整中斷程式內的參數。
練習:時鐘程式,在LCD上顯示時間,包含小時、分鐘及秒,含分隔符號(冒號:)共8位數(HH:MM:SS),靠第一行右邊顯示。
按0時,小時加1
按1時,分鐘加1
按2時,秒歸0
參考範例(ASM)
上述範例每按一次按鍵調整一次數值,有點不方便,為了調整成按著不放可以時間連續累加,直到接近所要的數值為止,我們可在程式加一段判斷程式,
第一次延遲時間長一點,若按住超過一段時間(程式中是設定成0.8秒),可連續累加(程式中是設定成0.15秒加1),各位可自行比較兩個程式不同的地方。
(控制參數命名為RPT,可用搜尋方式尋找)
參考範例(ASM)

LCD 命令 (如何控制LCM HD44780 晶片)

 源自於 http://www.geocities.com/dinceraydin/lcd/commands.htm
LCD Commands
The commands for HD44780 chip are shown in the table below. Scroll down to see the commands in binary, and more info on the entry mode set command.
INSTRUCTION
Decimal
Hexadecimal
Function set (8-bit interface, 2 lines, 5*7 Pixels)
56
38
Function set (8-bit interface, 1 line, 5*7 Pixels)
48
30
Function set (4-bit interface, 2 lines, 5*7 Pixels)
40
28
Function set (4-bit interface, 1 line, 5*7 Pixels)
32
20
Entry mode set
Scroll display one character right (all lines)
28
1E
Scroll display one character left (all lines)
24
18
Home (move cursor to top/left character position)
2
2
Move cursor one character left
16
10
Move cursor one character right
20
14
Turn on visible underline cursor
14
0E
Turn on visible blinking-block cursor
15
0F
Make cursor invisible
12
0C
Blank the display (without clearing)
8
08
Restore the display (with cursor hidden)
12
0C
Clear Screen
1
01
Set cursor position (DDRAM address)
128 + addr
80+ addr
Set pointer in character-generator RAM (CG RAM address)
64 + addr
40+ addr
Read DDRAM/CGRAM & Check Busy Flag
Entry mode set command
This command sets cursor move direction and display shift ON/OFF. There are 4 possible function set commands;04, 05, 06, and 07. This command changes the direction the cursor moves by setting the address counter to increment or decrement. This command is very important. If you do not understand it you may not see anything or what you actually wanted to see on LCD screen. I have created 4 animated gifs to demonstrate what the function set command is all about.
When my friend Hakan Dereli wanted to learn about LC displays I gave him an LC display and the 4*4 keyboard that I used with my Z80 system.The keyboard is based on a 74C922 chip and my circuit to convert the 4 bit data output of the 74C922 to 8 bit data.It also has 3 other buttons on it.This makes it great to experiment with LCDs by entering commands/data manually. Hakan tested all possible commands by sending all the numbers between 00h and FFh to the LCD to see if there is an undocumented feature and see how all commands work. He did not find anything undocumented, but he noted how LCD behaves after each function set command.
Below are the gifs to demonstrate those commands. To demonstrate the effect of each function set command it is assumed that the LCDs below are 2*16 LC Displays with DD RAM address set to 8 and underline cursor ON. Note that when the address counter is set to DECREMENT, strings sent to the LCD will be printed in reverse order. The same thing applies to the CG RAM, as well.

Entry mode set command 04h
Entry mode set command 04hDecrement Address Counter
Display Shift :OFF
String:Dereli

Entry mode set command 05h
Entry mode set command 05hDisplay Shift :ON
Decrement Address Counter
String :Hakan


Entry mode set command 06h
Entry mode set command 06hDisplay Shift :OFF
Increment Address Counter
String:Dereli


Entry mode set command 07h
Entry mode set command 07hDisplay Shift :ON
Increment Address Counter
String:Hakan

Checking the Busy Flag
To check the state of the busy flag and read the address counter
  1. Set R/W Pin of the LCD HIGH(read from the LCD)
  2. Select the instruction register by setting RS pin LOW
  3. Enable the LCD by Setting the enable pin HIGH
  4. The most significant bit of the LCD data bus is the state of the busy flag(1=Busy,0=ready to accept instructions/data).The other bits hold the current value of the address counter.
*This is a 1-micro-second instruction.

Complete command reference:

LAB13 BCD substrator (BCD減法器 9的補數方式)


LAB13 BCD substrator (BCD減法器 9的補數方式)






LAB10 BCD substrator (BCD減法器) 適用於DE2-70
a - b - bor_in  = {bor_out ,  diff_out}
0-0=0 , 9-0=9 , 0-9=-9

SW[7:4] 被減數  輸入
SW[3:0] 減數 輸入
HEX0 差  輸出
LEDG[0] 借位  輸出

//------------------------------------
//4-bit BCD substrator  9's Complement 
//Filename : BCD_substrator.v
//------------------------------------
module BCD_9s_comp (SW, LEDR, LEDG , CLOCK_27 ,KEY ,HEX0 ,HEX1 ,HEX2,HEX3 );

 input  [17:0] SW;    // toggle switches
 input  [7:0] KEY;       // Push bottom
 input  CLOCK_27;     //Clock 27MHz , 50Mhz

 output [17:0]LEDR;    // red  LEDS   
 output [8:0] LEDG;    // green LEDs
    
 output [6:0] HEX0,HEX1,HEX2,HEX3; //7-segment display
    
  

 //(Diff , Bor_out, Bor_in, A, B);
 //output Diff [3:0] S;  //Difference output
 //output Bor_out;    //Borrow out
 //input Bor_in;       //Borrow in
 //input [3:0] A, B;  //Input data  minuend /  subtrahend  A-B
 // A-B-Bor_in = Diff , Bor_out
 
 
   
    wire [3:0] A,B;   //Input data  minuend /  subtrahend  A-B
    wire [3:0] Diff_tmp;  //Difference output
    wire Bor_out;       //Carry out
    wire [7:0] segout0;   //HEX 0
    assign  A=SW[7:4] ;  //minuend A      
    assign  B=SW[3:0] ;  //subtrahend  B
 
    assign  LEDR[7:0]=SW[7:0];
    assign  LEDR[17]=SW[17];
    
    reg [3:0] A_tmp,B_tmp1;
    wire [3:0] S_tmp,B_tmp;
wire C4;
reg  [3:0] A_mod,B_mod;
 
    always @ ( A or B  )
begin
if (A<10)
A_tmp = A;   //若是>9 則為9
else
A_tmp =4'b1001;
  
if (B<10)
B_tmp1 = B;  //若是>9 則為9
else
B_tmp1 =4'b1001;
  
end
 
adder4 U0 (.S(B_tmp),    //9's Complement 
.Cout(), 
.A(4'b1010) , 
.B(~B_tmp1), 
.Cin(1'b0));
BCD_4bit_FA U1( .S1(S_tmp),
.Cout1(C4),
.Cin1(1'b0), 
.A1(A_tmp), 
.B1(B_tmp));

    assign Bor_out = ~C4;    
    always @ ( A_tmp or B_tmp or C4 or S_tmp )
begin
        case (Bor_out)
1 : begin 
B_mod = ~S_tmp; //Modified code
A_mod = 4'b1010;
end
0:  begin
B_mod = S_tmp;
A_mod = 4'b0000;
end
endcase
end

 
adder4 U2 ( .S(Diff_tmp),
.Cout(),
.A(A_mod), 
.B(B_mod),
.Cin(C4));     //C4 different 10's complement
  
   assign LEDG[0]=Bor_out;
   

_7seg UUT0(.hex((Diff_tmp)),
               .seg(segout0));
    
    assign HEX0=segout0[6:0];
    
   
    assign HEX1=7'b111_1111;
assign HEX2=7'b111_1111;
    assign HEX3=7'b111_1111;

    
endmodule



//----------------------
//4-bit unsigned adder
//Filename : adder4.v
//----------------------                                                                                                                                                                                                                   
module adder4(S, Cout, A, B, Cin);
 output [3:0] S;   //4-bit sum
 output Cout;    //Carry out
 input [3:0] A, B; //Inputs
 input Cin;    //Carry in

 //Assign the sum of (A+B+Cin) to Cout and Sum
 assign {Cout, S} = A + B + Cin;

endmodule

 module BCD_4bit_FA ( S1, Cout1, Cin1, A1, B1);
 
 output [3:0] S1; //Sumation output
 output Cout1;    //Carry out
 input Cin1;      //Carry in
 input [3:0] A1, B1;//Input data
 
 wire [3:0] A_tmp11,B_tmp11,S_tmp11;
 wire C41;
 reg [3:0] B_mod11;
 reg F1;

 //4-bit binary adder
 adder4 BINADD(
            .S(S_tmp11),
            .Cout(C41),
            .Cin(Cin1),
            .A(A1),
            .B(B1)
           );

 //Modify binary code with '0110'
 adder4 MODADD(
            .S(S1),
            .Cout(),
            .Cin(1'b0),
            .A(S_tmp11),
            .B(B_mod11)
           );

 always @ (Cin1 or A1 or B1 or C41 or S_tmp11)
 begin
 //F=C4+S3(S2+S1)
  F1 = (C41 | (S_tmp11[3] & (S_tmp11[2] | S_tmp11[1])));
  B_mod11 = {1'b0, F1, F1, 1'b0}; //Modified code
 end
 assign Cout1 = F1;

 endmodule



//-----------------------------------------
//Common-cathod seven segment display
//using case.....endcase statement
//Filename : sevenseg_case.v
//----------------------------------------- 
module _7seg(hex , seg);
    input  [3:0] hex;
    output [7:0] seg;
    reg    [7:0] seg;
    
        

 // segment encoding
 //      0
 //     ---  
 //  5 |   | 1
 //     ---   <- 6
 //  4 |   | 2
 //     ---
 //      3
 always @(hex)
 begin
  case (hex)
       // Dot point is always disable
       4'b0001 : seg = 8'b11111001;   //1 = F9H
       4'b0010 : seg = 8'b10100100;   //2 = A4H
       4'b0011 : seg = 8'b10110000;   //3 = B0H
       4'b0100 : seg = 8'b10011001;   //4 = 99H
       4'b0101 : seg = 8'b10010010;   //5 = 92H
       4'b0110 : seg = 8'b10000010;   //6 = 82H
       4'b0111 : seg = 8'b11111000;   //7 = F8H
       4'b1000 : seg = 8'b10000000;   //8 = 80H
       4'b1001 : seg = 8'b10010000;   //9 = 90H
       4'b1010 : seg = 8'b10001000;   //A = 88H
       4'b1011 : seg = 8'b10000011;   //b = 83H
       4'b1100 : seg = 8'b11000110;   //C = C6H
       4'b1101 : seg = 8'b10100001;   //d = A1H
       4'b1110 : seg = 8'b10000110;   //E = 86H
       4'b1111 : seg = 8'b10001110;   //F = 8EH
       default : seg = 8'b11000000;   //0 = C0H
     endcase
   end
   
endmodule



  清除項目編譯快取 執行 flutter clean 重新取得套件依賴 執行 flutter pub get 完整重新編譯並執行 flutter run 1. 新增專案套件 (pubspec.yaml) 在 Flutter 專案根目錄下的 pubspec.yaml 中,新增 ...