View Single Post
Old 15-06-2006, 03:20 PM   #10
falleaf
PIC Bang chủ
 
falleaf's Avatar
 
Tham gia ngày: May 2005
Bài gửi: 2,631
:
Send a message via Yahoo to falleaf
Source code

Phần khai báo

Code:
 title  "fuzzy2 - PIC18C452 Fuzzy Logic Fan Controller"
#define nDebug
;
;  This application uses the "fuzzyTECH" Heater/Motor control Interface
;   to implement a Fuzzy Logic Fan Controller on the PIC18C452.  To simplify the
;   software, the built in functions of the PICmicro to simplify the code development
;   tasks.  This application runs in two modes, a basic POT Interface and a fuzzy logic
;   control interface.  
;
;  The Difference between Fuzzy1 and Fuzzy2 is that Fuzzy2 Accepts Deltas to the PWM.
;   This was done to see if the Oscillations can be eliminated.  
;
;  Hardware Notes:
;  PIC18C452 running at 4 MHz with "_MCLR" pulled up
;  Clock is running with the 4x PLL Enabled
;  LED Displays:
#define Polling PORTB, 7
#define Sending PORTB, 6
#define Receive PORTB, 5
;  RA2 - Pot Input Pin
#define PotIn   PORTA, 2
;  RC2 - PWM Output Pin
#define PWMOut  PORTC, 2
;
;
  LIST R=DEC, F=INHX32
  INCLUDE "p18c452.inc"


;  Register Usage
 CBLOCK 0x000
TMR1Save:2						;  TMR1 Count Save Value
DDSave, DDOut:4						;  DecDisplay Variables
Dlay:3							;  Delay 1 Second
SetSpeed, DeltaSpeed, LEDTemp				;  Output Values
RXData:16						;  Want to Be able to Delete DPs
NewPWM, TempPWM						;  New PWM Value
 ENDC

;  Macros
TXOut Macro			;  Transmit the Data in "w"
 ifdef Debug
  nop
  nop
 else
  btfss   TXSTA, TRMT		;  Wait for the Previous Byte to be Sent
   bra    $ - (2 * 1)
 endif
  movwf   TXREG			;  Output the Digit 
  btg     Sending		;  Indicate Data Being Sent
 endm


 PAGE
 __CONFIG _CONFIG0, _CP_OFF_0
 __CONFIG _CONFIG1, _OSCS_OFF_1 & _HSPLL_OSC_1
 __CONFIG _CONFIG2, _PWRT_ON_2 & _BOR_ON_2 & _BORV_42_2
 __CONFIG _CONFIG3, _WDT_OFF_3 
 __CONFIG _CONFIG5, _CCP2MX_OFF_5     
 __CONFIG _CONFIG6, _STVR_OFF_6
                                ;  Note that the WatchDog Timer is OFF

;  Mainline of "Fuzzy1"
  org     0			;  Reset Vector

 variable i = 0			;  Clear the Start of Memory
 ifdef Delete
 while (i < 0x0100)
  nop
i = i + 1
 endw
 while (i < 0x0200)
  nop
i = i + 1
 endw
 while (i < 0x0300)
  nop
i = i + 1
 endw
 while (i < 0x0400)
  nop
i = i + 1
 endw
 while (i < 0x0500)
  nop
i = i + 1
 endw
 endif

  setf    PORTB
  clrf    TRISB			;  Use PORTB for Output

  movlw   0x002			;  Set ADC to Fosc/8, ADFM "Left" Justified
  movwf   ADCON1		;   AN2 is the ADC Select
  movlw   0x051				
  movwf   ADCON0

  movlw   200			;  Setup the 20 KHz PWM
  movwf   PR2
  movlw   0x004			;  On TMR2
  movwf   T2CON

  movlw   100			;  Start with a 50% Duty Cycle
  movwf   CCPR1L

  bcf     TRISC, 2

  movlw   0x00F			;  Enable PWM Mode
  movwf   CCP1CON

  movlw   0x020			;  Enable the RS-232 Port
  movwf   TXSTA
  movlw   0x090
  movwf   RCSTA

  movlw   25			;  Run the Data Output at 9600 bps
  movwf   SPBRG			;   - Note this is 2400 bps Except for the 

  movlw   0x002			;  Setup TMR1
  movwf   T1CON
falleaf vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn