|
شكرا أخي على الكود لكن لو تضعه كاملا يكون أفضل يعني ملف الاسمبلي كاملا بما فيه تعليمات delay1sec
ولدي سؤال؟
لماذا كان طلبك بلغة السي ولم يكن مباشرة بلغة الاسمبلي؟
|
حياك الله اخوي
السبب اني ابغى اتعلم ولو احد عطاني الكود مباشرة بالاسمبلي راح اتكاسل واعتمد
انا عندي خلفية بسيطة في الاسمبلي والسي والسي بلس بلس
عشان كذا طلبت افهم الفكرة بالسي ثم انا احاول اطبقها بالاسمبلي
وهذا الكود كامل
كود:
;*************************************************************************
; Project: Hallo World - LED at PORTB.0 is flashing
; Project file: hallo_world.mcp
; Source file: hallo_world.asm
; Author: Knorr
; Date: 02.02.2008
; Software: MPASM
; Hardware: PIC16F84A Programmer Module
;
; National language Code page: 850 (OEM - Multilingual Latin I)
;*************************************************************************
; ------------------------------------------------------------------------
; includes
; ------------------------------------------------------------------------
include "p16f84a.inc" ; definition for target controller
;-------------------------------------------------------------------------
; PIC configuration
; ------------------------------------------------------------------------
LIST p=16f84a
; define configuration word
; code protection off/ power up timer off/ wdt off /XT oscillator
__config 0x3ff9
; ------------------------------------------------------------------------
; Variables definition
; ------------------------------------------------------------------------
ct1 equ h'10'
ct2 equ h'11'
ct3 equ h'12'
ct4 equ h'13'
; ------------------------------------------------------------------------
; RESET Vector
; ------------------------------------------------------------------------
org 0x000
goto start
; ------------------------------------------------------------------------
; main program
; ------------------------------------------------------------------------
start: ; configure Port A and B
bsf STATUS,RP0 ; switch to register bank 1
movlw 0x00 ; PortB.0 define as output
movwf TRISB ; write direction register
movlw 0xff ; PortA define as input
movwf TRISA ; write direction register
bcf STATUS,RP0 ; switch to register bank 0
clrf PORTB ; set Port B to 0
main:
btfss PORTA,0
goto loop
movlw 0x01
xorwf PORTB,1
call delay1sec
loop:
btfss PORTA,1
goto loop1
movlw 0x02
xorwf PORTB,1
call delay1sec
loop1:
goto main ; go back to main
; ------------------------------------------------------------------------
; time delay
; 164*(1+2)*1æs +8æs =500æs (1 Machine cycle = 1æs if clock frequency is 4MHz )
; ------------------------------------------------------------------------
delay500us: ; (2MC) from the jump to subroutine
movlw D'164' ; (1MC) load register w with constant
movwf ct1 ; (1MC) move content of register w to ct1
nop ; (1MC)
w01:
decfsz ct1,f ; (1MC) decrement ct1 with target f
goto w01 ; (2MC) if ct1 != 0 -> w01, in other case
; skip the instruction
return ; (2MC + 1MC for NOP when 0)
; ------------------------------------------------------------------------
; time delay
; 200 * delay500us = 100ms
; ------------------------------------------------------------------------
delay100ms:
movlw D'200' ; load register w with constant
movwf ct2 ; move content of register w to ct2
w02:
call delay500us ; call the subroutine
decfsz ct2,f ; decrement ct2 with target f
goto w02 ; if ct2 != 0 -> w02, in other case
; skip the instruction
return
; ------------------------------------------------------------------------
; time delay
; 5 * delay100ms = 500ms
; ------------------------------------------------------------------------
delay500ms:
movlw D'5' ; load register w with constant
movwf ct3 ; move content of register w to ct2
w03:
call delay100ms ; call the subroutine
decfsz ct3,f ; decrement ct3 with target f
goto w03 ; if ct3 != 0 -> w03, in other case
; skip the instruction
return
; ------------------------------------------------------------------------
delay1sec:
movlw D'2' ; load register w with constant
movwf ct4 ; move content of register w to ct2
w04:
call delay500ms ; call the subroutine
decfsz ct4,f ; decrement ct3 with target f
goto w04 ; if ct3 != 0 -> w03, in other case
; skip the instruction
return
; ------------------------------------------------------------------------
end