2009年10月4日 星期日

MySQL: Convert character set and collation

Note there is no way to do this for all tables in pure MySQL, we can do the change for all columns in each existing table instead:
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name [COLLATE collation_name]

"ALTER TABLE" Syntax:
Know more about converting charset and collation:
http://dev.mysql.com/doc/refman/5.0/en/charset-conversion.html

2009年5月14日 星期四

SAC-86S 微机原理接口技术实验源码(7)


实验十 LED显示实验

实验内容:八位数码管从左向右逐位显示0-9的循环,之后显示稳定的98765432。
使用8255并行PA口作为段寄存器,PB口作为位寄存器。







;E10
;LED display,using 8255

code segment
assume cs:code
start:
mov AL,80H
out 1BH,AL ;set 8255 mode, PA PB out

lea DI,tab ;load effective addr of the table of the number code

s1:
mov CL,07FH
mov BX,0H
ss1:
mov AL,CL ;output must use Accumulator
out 19H,AL ;select bit
mov AL,[BX+DI]
out 18H,AL
call delay

ror CL,1 ;rotate right by 1 bit, without complementary bit
cmp CL,07FH
jnz ss1
inc BX
cmp BL,0AH ;0-9
jnz ss1

s2:
mov CL,0FEH
mov BX,0002H
ss2:
mov AL,CL
out 19H,AL
mov AL,[BX+DI]
out 18H,AL
call sdelay
rol CL,1
inc BX
cmp BL,0AH
jnz ss2
jmp s2

delay:
push CX
mov CX,0FFFFh
loop $
pop CX
ret

sdelay:
push CX
mov CX,0FFH
loop $
pop CX
ret
;table of number code
tab db 3FH;0
db 06H;1
db 5BH;2
db 4FH;3
db 66H;4
db 6DH;5
db 7DH;6
db 07H;7
db 7FH;8
db 6FH;9
db 77H;A
db 7CH;B
db 39H;C
db 5EH;D
db 79H;E
db 71H;F
code ends
end start

2009年5月13日 星期三

串口LED点阵显示屏-控制与应用实验源代码(3)

实验五 串行接口LED点阵显示屏
实验原理 15×14LED点阵,汉字编码设计为下上右左7×32,须将LED显示屏逻辑上视为7×32点阵。8032串行接口工作在模式0,功能为8位移位寄存器,串行移位输出LED显示屏列选通信号。行选通由P1并行口输出,最高位为移位输出控制位,高有效,P1.0-P1.7依次控制第1到7行。
显示过程为依次输出下上右左的四个字节的编码,再选通行(0FEH)让其显示并短暂延时。切换至下一行,即逻辑上的第二行(0FCH)时须暂时关闭显示,输出完第二行列选通后,左移行选通值使其显示,循环上述步骤,直至输出完全部七行。
注意:不同于全部点亮,输出完每个汉字后不再保持点亮状态,需循环显示直至1秒。延时用定时器中断实现。
附:
如何编制汉字代码:
按A->B->C->D的顺序进行编码。黑色部分为1。
15×14的显示屏全部点亮:
源代码:

;E5
;Serial LED array display
;Test program

ORG 0000H
LJMP STRT
ORG 001BH
LJMP TISR
ORG 0040H
STRT:
MOV TMOD,#10H
MOV SCON,#00H ;mode 0, serve as a shift register
;display for 1 seconds, just delay for 1 seconds will do, LED is still on
SETB TF1 ;TCON.7, force interrupt to initialize timer 1 in TISR
MOV IE,#88H ;EA,ET1 enable global and timer 1 interrupt

S1:
;test for all LEDs on
MOV P1,#80H
MOV SBUF,#0FFH
JNB TI,$
CLR TI
MOV SBUF,#0FFH
JNB TI,$
CLR TI
MOV SBUF,#0FFH
JNB TI,$
CLR TI
MOV SBUF,#0FFH
JNB TI,$
CLR TI
LCALL TDEL ;display for 1 sec
;need toggle off
LCALL OFF

;display name
S2:
MOV DPTR,#ZH ;get the last name
MOV R2,#0AH ;1 seconds
LCALL DISP
LCALL OFF ;turn off
LCALL TDEL

MOV DPTR,#BO ;get the first name
MOV R2,#0AH ;1 seconds
LCALL DISP
LCALL OFF ;turn off
LCALL TDEL
JMP S2

HERE: JMP $

DISP:
MOV R0,#0FEH ;the lowest bit control the line 1
MOV R1,#0H ;the offset from the table

DP1:
MOV P1,#0FFH ;toggle off
;LCALL OFF
;row:low-high, bottom-top order, serial output

MOV A,R1 ;first byte
MOVC A,@A+DPTR
MOV SBUF,A
JNB TI,$ ;wait for end of output
CLR TI

INC R1
MOV A,R1 ;second byte
MOVC A,@A+DPTR
MOV SBUF,A
JNB TI,$
CLR TI

INC R1
MOV A,R1 ;third byte
MOVC A,@A+DPTR
MOV SBUF,A
JNB TI,$
CLR TI

INC R1
MOV A,R1 ;fourth byte
MOVC A,@A+DPTR
MOV SBUF,A
JNB TI,$
CLR TI
INC R1

MOV P1,R0 ;select the row
LCALL SDEL

;select another row
MOV A,R0
RL A
MOV R0,A
CJNE R0,#0FEH,DP1 ;till all 7 lines are displayed

CJNE R2,#00H,DISP
RET

SDEL:
PUSH 0H
MOV R0,#0FFH
DJNZ R0,$
POP 0H
RET

OFF:
;temporarily turn off displaying when toggle lines
MOV P1,#0FFH
SDL1: JNB TF1,$;short delay 1, for 1/10 sec
RET

TDEL:
;delay for 1 second
SETB TR1;run timer 1, I think it is of no use
MOV R2,#0AH
WAIT:CJNE R2,#00H,$
RET

TISR:
;CPU will auto-clear TFx when interrupt occurs
;unlike Timer 0, need reload TL1/TH1 when INT happens
CLR TR1 ;stop timing
MOV TH1,#3CH;C350-FFFFH:50 000*2 us,timer cycle is 2 us
MOV TL1,#0AFH;INT PER 1/10 SEC
SETB TR1;run timer 1
DEC R2; 10 times for TISR as 1 seconds in total
RETI
;张
ZH:
DB 60H,7EH,00H,00H
DB 50H,02H,42H,7EH
DB 48H,42H,44H,02H
DB 54H,22H,48H,02H
DB 62H,1AH,50H,7EH
DB 41H,0EH,0FEH,40H
DB 00H,00H,0FEH,40H
;勃
BO:
DB 14H,08H,00H,10H
DB 14H,7EH,10H,10H
DB 14H,10H,10H,7CH
DB 14H,50H,10H,10H
DB 2CH,30H,7CH,0FFH
DB 44H,10H,14H,82H
DB 00H,00H,14H,7CH
END

2009年5月12日 星期二

步进电机-控制与应用实验源代码(2)

实验四 步进电机原理及应用
实验内容:编制MCS-51程序使步进电机以5转/分的速度正转两圈,停顿3秒后,以40转/分的速度持续反转。
注:使用定时器中断来控制延时。单片机为8032,定时器时钟为2µs。设定TH和TL初值来控制定时器计时长度(工作在16位模式),高八位TH、低八位TL,经初值*2µs时间后产生硬件中断,并自动将TF(定时器中断溢出)置1,调用中断服务程序,之后返回主程序。

;E4
;STEPPER MOTOR
;USING TIMER-1 INTERRUPT
ORG 0000H
LJMP STRT
ORG 001BH;TIMER 1 INT 001BH-0022H
LJMP TISR;TIMER INT SERVICE ROUTINE
ORG 0030H
STRT:
MOV TMOD,#00010000b ;mode: 16bit,timer 1
SETB TF1 ;TCON.7, force interrupt to initialize timer 1 in TISR
MOV IE,#88H ;EA,ET1 enable global and timer 1 interrupt

;spin clockwise, 2 circles
;96 steps
MOV R1,#60H
S1:
MOV A,#11H
SS1:
MOV R0,#08H
MOV P1,A
SS2:CJNE R0,#00H,$ ;wait 8 * 1/32 seconds
RL A ;rotate left
DEC R1
CJNE R1,#00H,SS1 ;loop 96 times

;wait 3 seconds
MOV R0,#60H
WAIT: CJNE R0,#00H,WAIT

;spin counter-clockwise, continuously
MOV A,#88H
S2:
MOV P1,A
SS3: JNB TF1,$ ;wait till INT
RR A ;rotate right
JMP S2

TISR:
;CPU will auto-clear TFx when interrupt occurs
;unlike Timer 0, need reload TL1/TH1 when INT happens
CLR TR1 ;stop timing
MOV TH1,#0C2H;7A12H-FFFFH:15625*2 us,timer cycle is 2 us
MOV TL1,#0F6H;INT PER 1/32 SEC
SETB TR1;run timer 1
DEC R0;8 times for each step in spin clockwise
;Note:DEC R0 is of no use for spin counter-clockwise
RETI
END

2009年5月7日 星期四

SAC-86S 微机原理接口技术实验源码(6)

实验9 8259中断优先级
实验内容 编写中断实验程序,使用8255PB口输出。IR0中断服务程序从PB口输出0FH,延时后返回主程序。IR1中断服务程序从PB口输出0F0H,延时并返回主程序。
ICW1设置为使用优先级(使用ICW4)、不使用级联,上升沿触发。
ICW2设置中断类型码,为所在中断向量表的起始地址(自定义中断部分)。
ICW4设置为全嵌套方式,优先级以IR0最高,依次递减;自动结束中断返回主程序。


;E9
;Interrupt controller 8259
;IR0 ISR: using PB to output 0FH to LEDs
;IR1 ISR: using PB to output 0F0H to LEDs

code segment
assume cs:code
start:
mov AL,80H
out 1BH,AL ;set 8255 mode:PB out

mov BX,80H ;from 80H on, can be defined by user
;INT vector table
;same as LEA ..
mov AX,offset ISR0
mov [BX],AX ;offset in code segment
mov AX,CS
mov [BX+2],AX;code segment addr

mov BX,80H ;INT type code*4 is where it is in vector table
mov AX,offset ISR1
mov [BX],AX ;offset in code segment
mov AX,CS
mov [BX+2],AX;code segment addr

;each 8259 has two port, which can be selected by A0
mov AL,00010011b; D0-need ICW4, D1-no cascading, D3-up edge
out 20H,AL ;ICW1
mov AL,00100000b;high 5 bits are INT type code, D0-D2 is auto filled by CPU
out 21H,AL ;ICW2
mov AL,00000111b;D4-all nested,D2-master,D1-auto cli,D0-8086CPU
out 21H,AL ;ICW4

STI ;start interrupt
T1: mov al,0FFH
out 19H,AL
jmp T1

;INT from IR0
ISR0:
push cx
mov cx,0FFFFH
r0:
mov AL,0FH
out 19H,AL
loop r0
pop cx
iret

;INT from IR1
ISR1:
push cx
mov cx,0FFFFH
r1:
mov AL,0FH
out 19H,AL
loop r1
pop cx
iret
code ends
end start

2009年4月30日 星期四

SAC-86S 微机原理接口技术实验源码(5)


实验8 8253定时计数器实验
8253计数器0分别工作在方式0、方式1、方式2下,由计数器2提供时钟。调用软件模拟示波器子程序输出波形。
Note:计数器2工作在方式3(方波发生器)下。



右图显示的是计数器0在方式2下的输出。



;E8
;Timer/Counter 8253

code segment
assume cs:code
start:
;Mode 0:Interrupt on Terminal Count, start counting from the initial COUNT value down to zero.
;
; Rate:input clock frequency
; OUT pin is set low after the Control Word is written
; remain low until couter reaches 0 and then OUT will be set high
; OUT will be set low when the counter is reloaded or the Control Word is written

;Mode 1:Hardware-Triggered One Shot
;
; used as monostable multivibrator. GATE input is used as trigger input.
; give an output pulse that is an integer number of clock pulses(one-shot)
; OUT will be initially high.
; OUT will go low on the CLK pulse following a trigger to begin the one-shot pulse
; remain low until the Counter reaches zero.
; OUT will then go high and remain high until the CLK pulse after the next trigger.
; can be retriggered during the pulse output

;Mode 2:Rate Generator
;
; acts as a divide-by-n counter, generates an impulse output every n clock cycles
; counting process will start the next clock cycle after COUNT is sent.
; OUT will then remain high until the counter reaches 1, and will go low for one clock pulse.
; OUT will then go high again, and the whole process repeats itself.
; when count is loaded between output pulses, the present period will not be affected.
; A new period will occur during the next count sequence.

mov AL,10110110b;command word, counter 2, mode 3
out 03H,AL ;lower byte first

mov AL,0FFH
out 02H,AL
mov AL,0FH
out 02H,AL

;mov AL,00010000b ;counter 0,mode 0
;mov AL,00010010b ;mode 1
mov AL,00010100b ;mode 2
out 03H,AL

mov AL,0FFH
out 00H,AL ;lower byte

CAL:
call AD
jmp CAL

;wave simulator
AD:
push DS
push DI
push CS
pop DS
LEA DI,ADDR
call dword ptr[DI]
pop DI
pop DS
RET
ADDR DW 67D0H,7000H
code ends
end start

2009年4月29日 星期三

SAC-86S 微机原理接口技术实验源码(4)


实验七 D/A 转换图形显示
实验内容:使用CPU向DAC0832送一组数据,DAC0832输出数据送0809的IN0通道,调用软件模拟示波器子程序AD,该子程序控制0809,使0809输出的数据在实验微机的CRT显示器上显示相应的波形。

;E7
;D/A converter to display the waves

code segment
assume cs:code
start:
call TRI
call LEV
call SAW
call SQR
jmp start
;wave of triangle
TRI:
mov AL,0H
TR1:
out 28H,AL ;set DAC0832, ADC0832 autostart
call DELAY ;delay for D/A converting
call AD

inc AL
cmp AL,04BH ;peak
jnz TR1

TR2:
out 28H,AL
call DELAY
call AD

dec AL
jnz TR2
call DELAY ;interval
RET
;wave of level
LEV:
mov AL,05H
LV1:
mov CX,04BH ;width
LV2:
out 28H,AL
call DELAY
call AD
loop LV2

add AL,1BH ;height of each level
cmp AL,56H ;total height,3 levels
jnz LV1
call DELAY ;interval
RET
;wave of raw
SAW:
mov AL,00H
SW:
out 28H,AL
call DELAY
call AD

inc AL
cmp AL,04BH ;peak
jnz SW
call DELAY ;interval
RET
;wave of square
SQR:
mov CX,4BH
mov AL,05H
SQ1:
out 28H,AL
call DELAY
call AD
loop SQ1

mov CX,4BH
mov AL,4BH
SQ2:
out 28H,AL
call DELAY
call AD
loop SQ2
call DELAY ;interval
RET
DELAY:
push CX
mov CX,0FFH
LP1:
loop LP1
pop CX
RET
;wave simulator
AD:
push DS
push DI
push CS
pop DS
LEA DI,ADDR
call dword ptr[DI]
pop DI
pop DS
RET
ADDR dw 67D0H,7000H
code ends
end start