Thursday, March 31, 2011

點字

00=黑黑黑黑.黑黑黑黑
01=黑黑黑黑.黑黑黑__
02=黑黑黑黑.黑黑__黑

7 6 5 4 3 2 1 0

Sunday, March 27, 2011

DJNZ的問題

mov A,#80
mov RR1,A
mov A,#2
MOV RR2,A
MOV A,#1
MOV RR3,A //R1 = 80 R2=2
POP A
KO: CLR P3.2
;mov a,#00H
MOVX @DPTR,A
SETB P3.2
INC DPTR
DJNZ R1,KO
DJNZ R2,KO
;DJNZ R3,KO
RET

但當R1跑了80次後,R2-1 = 1 此時R1要從 255開始跑


解法:
用mod概念
假設要480
480 = 255 * 1 + 225
所以r1 設 225
r2設2
就可以得到所求

Friday, March 25, 2011

SP指標位移

考慮下列程式
ORG 0 ;此時(SP)內容值為07H
MOV SP,#9F ;手動將(SP)改設9FH
MOV A,#7 ;A=07H
PUSH A ;(SP)+1 = 0A0H 0A0H=07H
PUSH A ;(SP)+1 = 0A1H 0A1H=07H
POP A ;取值A=07H (SP)-1 = 0A0H
CALL KOO ;設此句CODE為0BH,下句為0EH,則CALL後(SP)+1=0A1H (0A1H)=0EH
(SP)+1=0A2H (0A2H)=00H
KOO: ;假設
MOV A,1
RET ;DPH=(0A1H) (SP)-1 =0A0H DPL=(0A0H) (SP)-1 = 09FH


CALL執行時,會PUSH目前PC值的2BYTES ADDR進(SP)
RET執行時,先POP DPH再POP DPL
0A1H放DPL,0A2H放DPH ,所以完整的RETERN ADDR #000EH

RET

(PC)HIGH <- (sp)
(sp) <- (SP)-1
(PC) LOW <- (SP)
(SP) <- (SP)-1

若(SP) = 09H
PCHIGH = (09H)
PCLOW = (08H)

sp

sp

The Stack Pointer (SP

The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value. The Stack Pointer is used to indicate where the next value to be removed from the stack should be taken from.

POINTER指向下一個要被POP出去的東西

When you push a value onto the stack, the 8051 first increments the value of SP and then stores the value at the resulting memory location.

PUSH時,(SP)的值(ADDR)會+1,然後東西會存到(SP)+1的位置

When you pop a value off the stack, the 8051 returns the value from the memory location indicated by SP, and then decrements the value of SP.

POP時,先取值後,才把(SP) -1

This order of operation is important. When the 8051 is initialized SP will be initialized to 07h.

If you immediately push a value onto the stack, the value will be stored in Internal RAM address 08h.

初始的SP值是07H,所以第一個PUSH會被放在08H( INNER RAM )

This makes sense taking into account考慮到 what was mentioned two paragraphs above:

First the 8051 will increment the value of SP (from 07h to 08h) and then will store the pushed value at that memory address (08h).

SP is modified directly by the 8051 by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI. It is also used intrinsically whenever an interrupt is triggered (more on interrupts later. Dont worry about them for now!).



Thursday, March 24, 2011

SHCHR 未完

input
A : ascii code

------------------------------------
SHCHR: ;SHOW CHAR.
MOV DPTR,#EROW24
;CALCULATE PATTERN POSITION
MOV B,#48 ;48 BYTES FOR ONE CHAR
MOV R6,#24 ;24 rows/Char
MUL AB
;一個ascii 佔48bytes
;dptr = erow24 = 1st ascii (ascii code=0 [0~47])
;a*b = ascii code * 48 = 該字的1st byte address
ADD A,DPL
MOV DPL,A
MOV A,B
ADDC A,DPH
MOV DPH,A
;計算memory 位置
MOV A,ROW ;row似乎是1
RL A
RL A
RL A ;*8 ;*8仍是1
MOV B,#TOTCOL*3 ;80*3 //*3不知作啥用
MUL AB ;BA=ROW*1920=ROW*(80*24)
ADD A,COL ;col=2 a=1 -?> a=3
MOV R0,A ;r0=3
MOV A,B ;row * 1920的高位
ADDC A,#GBASE/256 ;a = 0 + c
MOV R1,A
PUSH P1
MOV P1,#0FFH

ASCII code table