|
Tài trợ cho PIC Vietnam |
MPASM Lập trình bằng hợp ngữ là một việc làm vô cùng vất vả, tuy nhiên, để hiểu và làm việc với vi điều khiển, hợp ngữ trở thành một công cụ khá đắc lực ... |
|
Ðiều Chỉnh | Xếp Bài |
12-05-2007, 06:37 PM | #7 | |
Đệ tử 1 túi
Tham gia ngày: Jul 2006
Bài gửi: 19
: |
lcd_gui anh namqn
Trích:
chương trình ở đây Code:
#include <p16f877a.inc> ;========================== Hien thi ra LCD ;===== Port B = D7 ... D0 ;===== RE0->RS; RE1->RW; RE2->E cblock 0X020 count delay x_delay endc ;========================== org 0X00 GOTO MAIN MAIN bsf STATUS,RP0 ; chon bank 1 movlw 0x00 movwf TRISE movwf TRISB MOVLW 0X83 MOVWF ADCON1 ;cac ngo dieu khien la digital bcf STATUS,RP0 ; chon bank 0 clrf PORTE clrf PORTB call dl100ms call dl100ms call dl100ms ;========================== start call lcdinit call dl100ms ;========================== call line1 call line2 call dl100ms call dl100ms goto $ ;========================== line1 movlw 081h ;dinh dia chi call address call st_line1 return ;========================== line2 movlw 0c7h ;dinh dia chi call address call st_line2 return ;========================== st_line1 clrf count bcf STATUS,2 display1 movf count,0 call text1 xorlw 0x00 btfsc STATUS,2 goto exit1 call display_lcd incf count,1 goto display1 exit1 bcf STATUS,2 return ;========================== st_line2 clrf count bcf STATUS,2 display2 movf count,0 call text2 xorlw 0x00 btfsc STATUS,2 goto exit2 call display_lcd incf count,1 goto display2 exit2 bcf STATUS,2 return ;==========================HIEN THI KI TU display_lcd bsf PORTE,2 ;set E nop nop bsf PORTE,0 ;set RS bcf PORTE,1 ;clr RW movwf PORTB call dl2ms bcf PORTE,2 ;clr E nop nop bcf PORTE,0 ;clr RS call dl100ms return ;==========================KHOI TAO LCD lcdinit bsf PORTE,2 ;set RS nop nop bcf PORTE,0 ;clr RS bcf PORTE,1 ;clr RW movlw 38h ;8 bits,2 lines movwf PORTB call dl2ms bcf PORTE,2 ;clr E call dl05ms ;================= bsf PORTE,2 nop nop bcf PORTE,0 bcf PORTE,1 movlw 0eh ;display on, cursor underline on,cursor blink off movwf PORTB call dl2ms bcf PORTE,2 call dl05ms ;================= call clrscr bsf PORTE,2 nop nop bcf PORTE,0 bcf PORTE,1 movlw 06h ;increment,display shift off movwf PORTB call dl2ms bcf PORTE,2 call dl05ms return ;========================== XOA MAN HINH clrscr bsf PORTE,2 ;set E nop nop bcf PORTE,0 ;clr RS bcf PORTE,1 ;clr RW movlw 01h movwf PORTB call dl2ms ;2mS bcf PORTE,2 call dl05ms ;05mS return ;================= ;============================GUI DIA CHI address bsf PORTE,2 ;set E nop nop bcf PORTE,0 ;clr RS bcf PORTE,1 ;clr RW movwf PORTB call dl100ms bcf PORTE,2 ;clr E call dl05ms return ;******************************************delay 0.5ms = 500uS dl05ms movlw D'165' ; +1 1 cycle movwf delay ; +2 1 cycle delay500_loop decfsz delay, F ; step1 1 cycle goto delay500_loop ; step2 2 cycles delay500_end return ; +3 2 cycles ;*********************************** delay 100ms dl100ms movlw D'200' ; +1 1 cycle movwf x_delay ; +1 1 cycle x_delay500_loop call dl05ms ; step1 wait 500uSec decfsz x_delay, F ; step2 1 cycle goto x_delay500_loop ; step3 2 cycles x_delay500_end return ; +2 2 cycles ;*********************************** delay 2ms dl2ms movlw D'4' ; +1 1 cycle movwf x_delay ; +1 1 cycle x_delay500_loop1 call dl05ms ; step1 wait 500uSec decfsz x_delay, F ; step2 1 cycle goto x_delay500_loop1 ; step3 2 cycles x_delay500_end1 return ;========================== text1 addwf 02h,1 retlw 'N' retlw 'H' retlw 'I' retlw 'E' retlw 'T' retlw ' ' retlw 'D' retlw 'O' retlw ' ' retlw 'P' retlw 'H' retlw 'O' retlw 'N' retlw 'G' retlw 0 text2 addwf 02h,1 retlw '3' retlw '0' retlw 0x0df retlw 'C' retlw 0 ;========================== END thay đổi nội dung bởi: namqn, 12-05-2007 lúc 06:52 PM. |
|
|
|