Thursday, 27 June 2013

Thursday, 20 June 2013

June 20 pcb





step motor, rs232 communication.

. ;-----------------------------------------
;ADC interrupt
;-----------------------------------------

ORG 0 ; reset vector
JMP main ; jump to the main program

ORG 3 ; external 0 interrupt vector
JMP ext0ISR ; jump to the external 0 ISR

ORG 0BH ; timer 0 interrupt vector
JMP timer0ISR ; jump to timer 0 ISR

ORG 30H ; main program starts here
main:
SETB IT0 ; set external 0 interrupt as edge-activated
SETB EX0 ; enable external 0 interrupt
CLR P0.7 ; enable DAC WR line
MOV TMOD, #2 ; set timer 0 as 8-bit auto-reload interval timer

MOV TH0, #0 ; |
    ; |

MOV TL0, #0fdh ; |
    ; |

SETB TR0 ; start timer 0
SETB ET0 ; enable timer 0 interrupt
SETB EA ; set the global interrupt enable bit
JMP $ ; jump back to the same line (ie: do nothing)

; end of main program


; timer 0 ISR - simply starts an ADC conversion
timer0ISR:
CLR P3.6 ; clear ADC WR line
SETB P3.6 ; then set it - this results in the required positive edge to start a conversion
RETI ; return from interrupt


; external 0 ISR - responds to the ADC conversion complete interrupt
ext0ISR:
CLR P3.7 ; clear the ADC RD line - this enables the data lines
MOV P1, P2 ; take the data from the ADC on P2 and send it to the DAC data lines on P1
SETB P3.7 ; disable the ADC data lines by setting RD
RETI ; return from interrupt

;-------------------------------------------------------
;serial communication - polling
;-----------------------------------------------------

cls11: ;code for state 11
cjne a, #11, cls12 ;save and confirm checksum
clr RI ;reset serial input
mov a, SBUF ;read serial buffer
mov cl_character, a
mov a, cl_checksum ;update checksum
add a, cl_character
mov cl_checksum, a
cjne a, #0, cls11l1 ;is checksum 0?
mov cl_next_state, #12 ;yes: proceed to state 12
ljmp cl_exit
cls11l1:
mov cl_next_state, #0 ;no: start over
ljmp cl_exit

cls80: ;code for state 80
cjne a, #80, cls81 ;save transaction id
clr RI ;reset serial input
mov a, SBUF ;read serial input
mov cl_character, a
mov cl_trans_id, a
mov a, cl_checksum ;update checksum
add a, cl_character
mov cl_checksum, a
mov cl_next_state, #81
ljmp cl_exit

cls81: ;code for state 81
cjne a, #81, cls100 ;is a character ready to be input?
jnb RI, cls81l1
mov cl_next_state, #11 ;yes: go to state 11
ljmp cl_exit
cls81l1:
mov cl_next_state, #81 ;no: stay here in state 81
ljmp cl_exit

cls100: ;xmt subroutine
cjne a, #100, cls101
jnb TI, cls100l1 ;jump if not ready
mov cl_next_state, #101
ljmp cl_exit
cls100l1:
mov cl_next_state, #100
ljmp cl_exit

cls101:
cjne a, #101, cls102
clr TI ;clr interrupt flag
mov SBUF, cl_xmt ;character to buffer
mov cl_next_state, cl_return
ljmp cl_exit

cls102: ;illegal state
lcall msg106 ;"COMMLINK PROCESS ILLEGAL STATE"
mov cl_next_state, #0

cl_exit:
mov a, cl_next_state
mov cl_state, a
ret

;-----------------------------------------------------------------------
;serial communication - interrupt
;-----------------------------------------------------------------

org 0 ;vector table setup
ljmp main ;reset to main
org 23h
ljmp uart_isr ;vector off to serial isr
org 30h start of main code
main:
mov p0, #offh ;initialize po as 8 inputs
mov tmod, #00100000b ;init timer1 auto reload (m2)
mov th1, #0fdh ;init timer1 for 9600 baud
mov scon, #01000000b ;init uart 8-n-1p; rx enabled
mov ie, #10010000b ;enable serial interrupts
setb tr1 ;start timer 1
back:
mov a, p0 ;read port 0
mov p1, a ;and echo it to both port 1
mov sbuf, a ; and the serial I/F
sjmp back ;loop endlessly

org 100h ;isr for the serial port
uart_isr:
jb ti, tx ;if ti then it's a tx interrupt
mov a, sbuf ; else it's rx so get char
clr ri ;clear ri interrupt flag
reti ;and leave
Tx:
clr ti ;it was a tx so clear ti flag
reti ;and leave
end

Wednesday, 19 June 2013

Friday, 14 June 2013

ADC, DAC


ADC

analog signal too small
amplify, level shifting

analog signal too big
attenuate, level shifting
http://www.ti.com/lit/an/sboa097a/sboa097a.pdf


DAC

8051

ORG 0 ; reset vector
JMP main ; jump to the main program

ORG 3 ; external 0 interrupt vector
JMP ext0ISR ; jump to the external 0 ISR

ORG 0BH ; timer 0 interrupt vector
JMP timer0ISR ; jump to timer 0 ISR

ORG 30H ; main program starts here
main:
SETB IT0 ; set external 0 interrupt as edge-activated
SETB EX0 ; enable external 0 interrupt
CLR P0.7 ; enable DAC WR line
MOV TMOD, #2 ; set timer 0 as 8-bit auto-reload interval timer

MOV TH0, #-50 ; | put -50 into timer 0 high-byte - this reload value,
    ; | with system clock of 12 MHz, will result in a timer 0 overflow every 50 us

MOV TL0, #-50 ; | put the same value in the low byte to ensure the timer starts counting from
    ; | 236 (256 - 50) rather than 0

SETB TR0 ; start timer 0
SETB ET0 ; enable timer 0 interrupt
SETB EA ; set the global interrupt enable bit
JMP $ ; jump back to the same line (ie: do nothing)

; end of main program


; timer 0 ISR - simply starts an ADC conversion
timer0ISR:
CLR P3.6 ; clear ADC WR line
SETB P3.6 ; then set it - this results in the required positive edge to start a conversion
RETI ; return from interrupt


; external 0 ISR - responds to the ADC conversion complete interrupt
ext0ISR:
CLR P3.7 ; clear the ADC RD line - this enables the data lines
MOV P1, P2 ; take the data from the ADC on P2 and send it to the DAC data lines on P1
SETB P3.7 ; disable the ADC data lines by setting RD
RETI ; return from interrupt

Wednesday, 12 June 2013

雪山飞狐

http://www.youtube.com/watch?v=knOpG7oCf4Y


程灵素

  一、可以不美丽,但是不能自卑。灵素mm长得不好看,面黄肌瘦、发育不良。这不是问题,生活中有那么多长相平平的女人,一样得觅佳偶,简爱不还长得丑了么,加上灵素的强大气场,胡斐其实也数次动心,心里道你绝不是丑姑娘。可是,由于长得不好看,灵素mm自小就饱受打击,姐姐也鄙视她,导致了她极度的自卑。在和胡斐的交往中更是如此,她愿意为胡斐付出一切,却从不敢说出口,天天装着一付风轻云淡的姿态,其实心底就是自卑不敢表现的火热,怕再次受胡斐伤害。这是她和赵敏的本质不同,同样爱的深,同样智计百出,赵敏的光环是炽热的红色,一往无前去追求,碰到任何困难都在微笑;而灵素mm的光环是忧郁的蓝色,小心翼翼的蜷缩在脆弱的面具后,碰到困难她也解决(不同于小龙女的逃避),但她解决时候心里带着是怨气不是爱意。
  二、可以太聪明,但是别把别人当傻子。灵素mm算无遗策没有问题,但是她一直把胡斐当小孩子一样耍。不告诉人为什么,就只要按着她指示办就行。是,你牛逼,但是也没必要让人家傻子似的团团转,最后搞定了再给人讲解下原因吧。当然,这也因为她在其他方面的自卑,导致她在智力上补偿性的找场子回来。有人说灵素这是控制欲强,从出场耍胡斐,到最后死也全给胡斐安排妥当了,胡斐只能按照灵素说的亦步亦趋,所以胡斐不喜欢灵素。其实控制欲强也不是问题,关键不能破坏人格平等。
  人格平等是任何爱情的必备前提,但凡破坏这个前提的,没有能有好下场的。
  无论你是自卑到爱的卑微,将自己从属于人,或者自大到爱的霸道,将自己凌驾于人;都没有好下场。
  固然,男欢女爱中,总有主动有被动,总有斗争有妥协,总有人要扮演全智贤有人要扮演车太贤,有人要做红太狼有人要做灰太狼,但记住,一切妥协都是以不伤害人格平等为前提的。
  三、可以自卑、可以把人当傻子,但是绝对不可以没眼光。其实灵素mm很好很好的,上面说的两宗罪也不是非犯不可,犯了也不是不可饶恕,关键看跟谁。胡斐这种人,根本就不适合灵素,或者说配不上灵素。灵素mm佳偶应该要么有郭靖这样山一般气度、要么像无忌一样优柔寡断、要么干脆就像小鱼儿一样比她更聪明的(如同苏樱完克小鱼儿)。像胡斐这种带点聪明劲,其实不咋地,格局又不大的男生,不是良配啊。(我都比他强)可惜灵素mm接触范围太窄,身边没几个异性,一碰见胡斐这样的正常人形生物就缴械投降了……
  正如第一讲说的,没有最完美,只有最合适。灵素mm所有的特点到我这可能都成仙女了,可惜胡斐没我这品味。
  我非常喜欢灵素,她一死,飞狐全书便死,再也没有心气看下去了。不过不能怪金老爷子,这样一个大格局、大智慧的女性,不塑造成悲情人物、不写死她,又怎能放得出烟花般璀璨的生命呢?
  最后启示篇,模仿下古龙。
  第一个破绽不是容貌,而是自卑。
  第二个破绽不是聪明,而是霸道。
  第三个破绽不是破绽,而是选择。
  所以,
  最快的剑不是美貌,而是微笑。
  最利的刀不是装傻,而是尊重。
  最强的枪不是完美,而是眼光!
  能进能退 乃真正法器