قسم الميكروكنترولر والروبوت ودوائر الاتصال بالحاسب الالي قسم المتحكمات الـ microcontroller و المعالجات microprocessor و التحكم الرقمي بالكمبيوتر CNC والانظمة الآلية والروبوت Robots

أدوات الموضوع

forget me now
:: مهندس ::
تاريخ التسجيل: Jun 2007
المشاركات: 24
نشاط [ forget me now ]
قوة السمعة:0
قديم 01-01-2008, 05:09 PM المشاركة 1   
not funny pwm program using pic 16f84a Twitter FaceBook Google+



هدا البرنامج يحتوي على مفتاحين لاختيار قيمه الخرج من 0 or40% or80% or 100%
والمخرج ل pwm علىRB1

; This file is a basic code template for assembly code generation *
; on the PIC16F84A. This file contains the basic code *
; building blocks to build upon. *
; *
; If interrupts are not used all code presented between the ORG *
; 0x004 directive and the label main can be removed. In addition *
; the variable assignments for 'w_temp' and 'status_temp' can *
; be removed. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
; Template file built using MPLAB V4.00 with MPASM V2.20 and *
; MPLINK 1.20 as the language tools. *
; *
;************************************************* *********************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;************************************************* *********************
; *
; Files required: *
; *
; *
; *
;************************************************* *********************
; *
; Notes: *
; *
; *
; *
; *
;************************************************* *********************

list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.


;***** VARIABLE DEFINITIONS (examples)
; example of using Uninitialized Data Section
INT_VAR UDATA 0x0C
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
TIMER_L RES 1
TIMER_H RES 1


; example of using Overlayed Uninitialized Data Section
; in this example both variables are assigned the same GPR location by linker
G_DATA UDATA_OVR ; explicit address can be specified
flag RES 2 ; temporary variable (shared locations - G_DATA)
G_DATA UDATA_OVR
count RES 2 ; temporary variable (shared locations - G_DATA)


;************************************************* *********************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto start ; go to beginning of program

INT_VECTOR CODE 0x004 ; interrupt vector location
goto INTERRUPT
MAIN CODE
INTERRUPT
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register

; isr code can go here or be located as a call subroutine elsewhere

movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt

start
nop ; code starts here (example)
banksel flag ; example
clrf flag ; example
; remaining code goes here
BSF STATUS,5 ;BANK1
CLRF TRISA ;PORTA IS OUTPOT
MOVLW 0XFF
MOVWF TRISB ;PORTB IS INPUT

BCF STATUS,5 ;BANK0
CLRF PORTA
again ;;;;;;TO REPEAT THE PROGRAM;;;;;;;;;;;;;;;;;;;;;;;;;;;
nop ;to elimniate the fractions from the calculaton
nop ; or to minimize the error
BTFSS PORTB,7
GOTO ZERO_OR_40 ;ifRB7=0
GOTO MAX_OR_80 ;ifRB7=1
ZERO_OR_40
nop
BTFSS PORTB,6
GOTO ZERO ;if RB6=0&&RB7=0
GOTO OR_40 ;if RB6=1&&RB7=0
MAX_OR_80
BTFSC PORTB,6
GOTO MAX ;if RB6=1&&RB7=1
GOTO OR_80 ;if RB6=0&&RB7=1
ZERO
nop
nop
MOVLW D'77' ;100% OFF
MOVWF TIMER_L
CLRf TIMER_H ;W=0
BCF PORTA,0 ;TURN OFF LED
GOTO PWM
OR_40
MOVLW D'42' ;60% OFF
MOVWF TIMER_L
MOVLW D'34' ;40% ON
MOVWF TIMER_H
BSF PORTA,0 ;TURN ON LED
GOTO PWM
OR_80
MOVLW D'8' ;20% OFF
MOVWF TIMER_L
MOVLW D'68' ;80% OF 255(ON)
MOVWF TIMER_H
BSF PORTA,0 ;TURN ON LED
GOTO PWM
MAX
BSF PORTA,1 ;TURN ON MOTOR
BCF PORTA,0 ;TURN OFF LED
GOTO again ; PWM
PWM
;;;;;;;;;;;;;;;TURN OFF MOTOR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;WHEN TIMER_L=0;;;;;;
CLRW
SUBWF TIMER_L
BTFSC STATUS,2 ; Z=1 WHEN TIMER_L=0
GOTO BUG_2
;;;;;;;;;;;;;;;;;;;;;;;;;
LOOP2
DECFSZ TIMER_L
GOTO LOOP2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;
BUG_2
CLRW
SUBWF TIMER_H
BTFSC STATUS,2 ; Z=1 WHEN TIMER_H=0
GOTO BUG_1
BUG_BUG ;USED AT MAX TO MINIMIZE T_OFF
;;;;;;;;;;;;;;;TURN ON MOTOR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BSF PORTA,1 ;TURN ON MOTOR
LOOP1
DECFSZ TIMER_H
GOTO LOOP1
BUG_1 ;WHEN TIMER_H=0
BCF PORTA,1 ;TURN OFF MOTOR
GOTO again

END ; directive 'end of program'

اعلانات

forget me now
:: مهندس ::
تاريخ التسجيل: Jun 2007
المشاركات: 24
نشاط [ forget me now ]
قوة السمعة:0
قديم 01-01-2008, 05:13 PM المشاركة 2   
not funny


تم كتابه هدا البرنامج بلغه الاسمبلي وباستخدام الmplab

اعلانات اضافية ( قم بتسجيل الدخول لاخفائها )
  

الصورة الرمزية aladdin_2005
aladdin_2005
:: عضو ذهبي ::
تاريخ التسجيل: Apr 2004
الدولة: مصر ((الأسكندريه))
المشاركات: 1,246
نشاط [ aladdin_2005 ]
قوة السمعة:115
قديم 06-01-2008, 11:00 AM المشاركة 3   
افتراضي


بارك الله فيك اخي الحبيب
هل يمكنك اضافة رسم للهارد وير اضافة تعليقات حول كيفية الإستفاده من هذا المشروع القيم

إضافة رد

العلامات المرجعية

«     الموضوع السابق       الموضوع التالي    »
أدوات الموضوع

الانتقال السريع إلى


الساعة معتمدة بتوقيت جرينتش +3 الساعة الآن: 08:23 AM
موقع القرية الالكترونية غير مسؤول عن أي اتفاق تجاري أو تعاوني بين الأعضاء
فعلى كل شخص تحمل مسئولية نفسه إتجاه مايقوم به من بيع وشراء وإتفاق وأعطاء معلومات موقعه
التعليقات المنشورة لا تعبر عن رأي موقع القرية الالكترونية ولايتحمل الموقع أي مسؤولية قانونية حيال ذلك (ويتحمل كاتبها مسؤولية النشر)

Powered by vBulletin® Version 3.8.6, Copyright ©2000 - 2025