![](https://imageproxy.pixnet.cc/imgproxy?url=../images/oUmDrga7t3XmDPprU8pHZA.jpg)
The design is captured from the web link below
http://hw.cz/constrc/lc_metr/
initial test result -
lc.hex, it works but improvement is required (download here), ROM 1741 bytes
lc_v2.hex, it does NOT works, do not know why
programming kit - review http://hk.myblog.yahoo.com/xiao-laba/article?mid=2346
log book -
AT89C2051 LC meter 測量電容量或者電感量的儀表
為甚麼俺要浪費時間複製人家在2002年已經做過的事情? 原因很簡單, 人類在幾千年前就會燒烤了, 今天還是有很多人喜歡 BBQ, 因為學習的過程是不斷累積經驗, 人家會做的, 俺卻還沒有學會, 所以老老實實地從零開始學. 最終的目的 -
1) 有一個 LC 錶可以用 (買個商品, 現在大概 NT$1600 - NT$2000)
2) 理解 LC 和震盪頻率的關係
3) 學習人家的設計
基本上網上很多 LC meter DIY 的版本, 原理都是一樣的 - 震盪電路加上不同 MCU 的組合,
1) 測量基本 LC 所產生的震盪頻率 F0
2) 待測電容或電感, 並連到基本 LC 後, 得到的變化震盪頻率 Delta_F, 用作推算待測的 L 或 C的大小.
3) MCU 負責接收 LC 產生的震盪訊號, 計算其頻率, 並顯示計算的結果.
改進的計畫 (Improvement plan)
1) 省去校正的開關 (or relay), POWER ON 替代
2) LCD 對比度控制用固定普通電阻, 省去 VR
3) 重新畫線路圖, 因為原作的實在看到眼花繚亂, 初期很難明白
;====================================
; APR/28/2010, http://hk.myblog.yahoo.com/xiao-laba/article?mid=2597
; simulator run for this routine,
; XTAL = 12Mhz
; Entry : ACC = 120
; Exit : ACC, scratched
; total cycle time = 1.2ms = 1200us
; rotuine cycle time = 1200us / 120 = 10us
; hence this routine designed as 10us x #Acc
Delay:
PUSH ACC ;[24] save ACC
MOV A,#02H ;[12] Acc = 2, dummy instruction
MOV A,#01H ;[12] Acc = 1, dummy instruction
Delay1:
DJNZ ACC,Delay1 ;[24] Acc = 1 - 1 = 0, goto next instruction
POP ACC ;[24]
DJNZ ACC,Delay ;[24]
RET ;[24]
;====================================
;====================================
; Initializing the HD44780 compatible LCD with 4-bit mode
;
; APR/28/2010, http://hk.myblog.yahoo.com/xiao-laba/article?mid=2597
; simulator run for this routine,
; XTAL = 12Mhz
; Entry : N/A
; Exit : ACC,r1, scratched
Init_LCD:
; in 4-bit mode, data sent as nibbles
; i.e. data = 0x23,
; send higher nibble first, it is 2
; then lower nibble, it is 3
; To enable LCD in uses 4 bit mode, power_on then
; reset it as following,
; 1. Wait 20mS
; 2. Send 1st init value (0x30)
; 3. Wait 10mS
; 4. Send 2nd init value (0x30)
; 5. Wait 1mS
; 6. Send 3rd init value (0x30)
; 7. Wait 1mS
; 8. Select bus width (0x30 - for 8-bit and 0x20 for 4-bit)
; 9. Wait 1mS
; done, reetted to 4 bit mode
CLR LCD_E ; LCD_E = 0
CLR LCD_RS ; LCD_RS = 0
; CLR LCD_RW ; LCD_RW = 0, WRITE mode only
mov a,#30h ; 1st init value for LCD
mov r1,#20 ; delay of 20 x 1.2ms
acall Init_LCD_command
mov a,#30h ; 2nd init value for LCD
mov r1,#5 ; delay of 5 x 1.2ms
acall Init_LCD_command
mov a,#30h ; 3rd init value for LCD
mov r1,#1 ; delay of 1 x 1.2ms
acall Init_LCD_command
mov a,#20h ; 0x20 - 4 bit mode
; 0x80 - 8 bit mode
mov r1,#1 ; delay of 1 x 1.2ms
acall Init_LCD_command
ret
Init_LCD_command:
; ACC high nibble shift to D7-D4 of LCD interface
; this design can use any combination of port & pin
; no lower nibble taking care with original design
rlc a ; bit 7 rolled to C bit
mov D7_R4,C ; move C bit to LCD_D7 pin
rlc a ; bit 6 rolled to C bit
mov D6_R3,C ; move C bit to LCD_D6 pin
rlc a ; bit 5 rolled to C bit
mov D5_R2,C ; move C bit to LCD_D5 pin
rlc a ; bit 4 rolled to C bit
mov D4_R1,C ; move C bit to LCD_D4 pin
Init_LCD_wait:
; time delay for LCD initialization
MOV A,#120
acall soft_delay_1ms_x_Acc ; delay 1.2 ms
djnz r1,Init_LCD_wait ; delay r1 x 1,2ms
SETB LCD_E ; LCD_Enable = H
nop ; nop
CLR LCD_E ; LCD_Enable = L
ret
;====================================