📄 sinewave.lst
字号:
MPASM 02.20.04 Intermediate SINEWAVE.ASM 9-9-1999 11:21:06 PAGE 1
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00001 ;**********************************************************************************
00002 ; sinewave.asm
00003 ;
00004 ; Version 1.02 9th September 1999
00005 ;
00006 ; Software to time slice a 50Hz Mains Sinewave to give even power increments.
00007 ; Input from 4 Pins:
00008 ; Up - Increases power by 1%
00009 ; Down - Decreases power by 1%
00010 ; On - Sets Power to 100%
00011 ; Off - Sets Power to 0%
00012 ;
00013 ; Software designed for use with 12C50x Using internal 4MHz Oscillator giving
00014 ; an instruction cycle time of 1uS.
00015 ; This software has carefully timed loops that act as delays as well as checking
00016 ; for input from the user.
00017 ;
00018 ; Author: Michael Pearce
00019 ; Chemistry Department, university Of Canterbury
00020 ;
00021 ; Started: 16 July 1998
00022 ;
00023 ;*********************************************************************************
00024 ; VERSION INFORMATION
00025 ; (Current Version On top)
00026 ; Version 1.02 - 9 September 1999
00027 ; - Attempt to correct the timing values by re-including the 100% check
00028 ;
00029 ; Version 1.01 - 23 July 1998
00030 ; - Added Calibration of Xtal to overcome timing problems using different
00031 ; devices. The OTP I used was different to the EPROM device timing wise.
00032 ; - May Need to alter Timing values to suit (Haven't Done Yet)
00033 ;
00034 ;
00035 ; Version 1.00 - 23 July 1998
00036 ; - All found bugs removed and testing was sucessful
00037 ; - First OTP device Programmed and Used (Found Timing difference)
00038 ;
00039 ;**********************************************************************************
00040 ;
00041 ; UpButton ; Input PIN - Increments Power in 1% steps (Lowest Priority)
00042 ; DownButton ; Input PIN - Decrements Power in 1% steps (Second Lowest Priority)
00043 ; OnPin ; Input PIN - Switches Power to 100% (Second Highest Priority)
00044 ; OffPin ; Input PIN - Turns Power OFF (Highest Priority)
00045 ; Output ; Output PIN - Strikes the LED to Start the TRIAC
00046 ; ZeroCross ; Input PIN - Indicates zero cross - used for wakeup!!
00047 ;
00048 ; UpFlag ; Indicator Flag - Indicates that Up Pin previously "High"
00049 ; DownFlag ; Indicator Flag - Indicates that Down Pin previously "Low"
00050 ; NoPower ; Indicator Flag - Indicates that Zero Power Required
00051 ;
00052 ; Power ; Data Byte - Power Level Percentage Setting Variable
00053 ; Count ; Num Of Cycles to wait before switching Power ON
MPASM 02.20.04 Intermediate SINEWAVE.ASM 9-9-1999 11:21:06 PAGE 2
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00054 ; CountTotal ; Total Num of loops Per Cycle
00055
00056
00057 ;*******************************************************************
00058 ; REQUIRED SET UP in Hardware!!
00059 ;
00060 ; Low Going Edge 400uS before actual zero of 4ns Minimum low time!!
00061 ;
00062 ; Inputs are active LOW, pulled high externally by 10K resistors
00063 ;
00064 ;*******************************************************************
00065
00066
00067
00068
00069 ; LIST P=12C508,F=INHX8M
00070
00071 ; INCLUDE "picreg.equ"
00072 INCLUDE "P12C508.inc"
00001 LIST
00002 ; P12C508.INC Standard Header File, Version 1.02 Microchip Technology, Inc.
00105 LIST
00073
00074
00075
00076 ;******* I/O Port Addresses ******
00077 #define UpButton GPIO,5
00078 #define DownButton GPIO,4
00079 #define OnPin GPIO,3
00080 #define OffPin GPIO,2
00081 #define ZeroCross GPIO,0
00082
00083
00084 #define Output 0x06,1 ;-- Toggle TRIS to toggle pin
00085
00086
00087 ;****** Timing Info *******
00088 #define TIMEOUT 0xF1 ;-- Longest time alowed 0xf1 * 38
00089
00090
00091 ;****** BIT FLAGS ******
00092 #define UpFlag 0x07,0
00093 #define DownFlag 0x07,1
00094 #define NoPower 0x07,3
00095
00096 #define MASK_SLEEP b'00110111' ;-- Set TRIS so GP3 won't cause Wake from sleep
00097 #define MASK_ON b'00111101' ;-- Turn Output ON
00098 #define MASK_OFF b'00111111' ;-- Turn Output OFF
00099
00100
00101 ;****** DATA Locations *****
00102
00000008 00103 Power EQU 0x08
MPASM 02.20.04 Intermediate SINEWAVE.ASM 9-9-1999 11:21:06 PAGE 3
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
00000009 00104 Count EQU 0x09
0000000A 00105 CountTotal EQU 0x0A
0000000B 00106 Delay1 EQU 0x0B ;-- Used to generate 3mS delay...
0000000C 00107 Delay2 EQU 0x0C ; .... till actual zero cross.
00108
00109
00110
00111 ;**********************************************************************************
00112 ; Equates for this program
00113 ;**********************************************************************************
00114
00000010 00115 TEMP equ 0x10
00000001 00116 adif equ 1
00000002 00117 adgo equ 2
00118
00119 ;**********************************************************************************
00120 ; Reset address and interupts
00121 ;**********************************************************************************
0000 00122 org 0x00
00123 ;----- Load Calibration Settings for XTAL ------
0000 0025 00124 MOVWF OSCCAL ;-- W is loaded with value on RESET
00125 ;-----------------------------------------------
0001 0A10 00126 goto start
00127
0004 00128 org 0x04
0004 0800 00129 return ;interupt vector
00130
00131 ;**********************************************************************************
00132 ; Start - Begining of main program - Initialise then Run.
00133 ;**********************************************************************************
0010 00134 ORG 0x10
0010 0000 00135 start NOP
0011 0000 00136 NOP
0012 0000 00137 NOP
0013 0000 00138 NOP
00139
0014 0066 00140 CLRF GPIO ;-- Set all OUTPUT states to Zero
0015 0CFF 00141 MOVLW 0xFF ;-- All as Inputs - Toggle Bit For GP6 to change output
0016 0006 00142 TRIS GPIO ;-- Load the TRIS Register
0017 0C4F 00143 MOVLW 0x4F ;-- Wake up on change + disable pull ups
0018 0002 00144 OPTION
00145
0019 0068 00146 CLRF Power ;-- Clear the Power Setting
00147
00148 ;**********************************************************************************
00149 ; MainLoop - This is the main Loop of the program
00150 ;**********************************************************************************
001A 00151 MainLoop
00152
00153 ;******** Check if POwer > 100 %
001A 0C64 00154 MOVLW 0x64 ; Load 100% into Reg for checking if > 100%
001B 0088 00155 SUBWF Power,W ; Subtract 100 from Power Rating
001C 0703 00156 BTFSS STATUS,C ; Check if result +ve of -ve
MPASM 02.20.04 Intermediate SINEWAVE.ASM 9-9-1999 11:21:06 PAGE 4
LOC OBJECT CODE LINE SOURCE TEXT
VALUE
001D 0A21 00157 GOTO MaxEnd1 ; result was positive so no need to adjust the setting
001E 0C64 00158 MOVLW 0x64 ; Result -ve so adjust the power
001F 0028 00159 MOVWF Power ;
0020 0A21 00160 GOTO MaxEnd
0021 00161 MaxEnd1
0021 00162 MaxEnd
00163
00164 ;**********
00165
0021 0467 00166 BCF NoPower ;-- Enable The Power Bit
0022 0CF1 00167 MOVLW TIMEOUT ;-- Load Total Numer of timing loops to Do
0023 002A 00168 MOVWF CountTotal ;-- MAX Before Coming back to here
0024 0208 00169 MOVF Power,W ;-- Load Power Rating to use as Offset
0025 0964 00170 CALL PowerTable ;-- Get the data from the table
0026 0029 00171 MOVWF Count ;-- Store in Count Register
00172
0027 0208 00173 MOVF Power,W
0028 0643 00174 BTFSC STATUS,Z ;-- Test the zero flag
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -