📄 main.s
字号:
cpu LMM
.module main.c
.area text(rom, con, rel)
.dbfile ./main.c
.dbfunc e main _main fV
_main::
.dbline -1
.dbline 93
; //---------------------------------------------------------------------
; //
; // Name: CSR_7Button_Demo_v2.1
; // - 4/1/06 - version 2.1 (XCH)
; // - removed function call to output
; // count values
; // - added output of CSR_baSwOnMask[0]
; // to LCD
; // - 3/20/06 - version 2.0 (XCH)
; // - added Calibration routine
; // - adjusted settings
; //
; // For Board: CY3212-CapSense RevA
; // Chip: CY8C21434-24LFXI
; //
; // Description:
; // This code determines which switch is depressed among 7 switches
; // and displays that switch number on the LCD display. This project uses
; // Period method of measurement. The display on LCD (port 2 in the LCD UM
; // parameters) will display the value of CSR_baSwOnMask[0]. This variable
; // holds the on/off status of the 7 switches as a bitmask. Then once switch
; // is pressed, the switch number is displayed on the LCD display. The
; // switch numbers and port pins are assigned in UM wizard.
; //
; // Project Settings (in the Device Editor):
; //
; // Global Resources:
; // Power Setting [Vcc/SysClk freq]: 5.0V / 24MHz
; // CPU_Clock: SysClk/1
; //
; // User Module Parameters:
; // Method: Period
; // FingerThreshold: 100
; // NoiseThreshold: 40
; // BaselineUpdateRate: 40
; // ESDDebounce: Disabled
; //
; // Switch to port settings in CSR wizard (for CY3212 demo board)
; //
; // SW0 -> P1[4]
; // SW1 -> P1[6]
; // SW2 -> P3[0]
; // SW3 -> P3[2]
; // SW4 -> P3[3]
; // SW5 -> P3[1]
; // SW6 -> P1[3]
; //
; // Notes:
; // CSR_1_baSwOnMask -> is an array of BYTEs that contains the data
; // that determines which button has been pressed. The first
; // byte CSR_1_baSwOnMask[0] holds the on/off state of the first 8 switches
; // in the system, CSR_1_baSwOnMask[1] would hold the on/off state of the
; // next 8 switches in the system. Since there are only 7 switches in
; // this particular system we only use CSR_1_baSwOnMask[0].
; // Th LSb (bit 0) represents the state of switch0:
; // 0 = off
; // 1 = on
; // Bit 1 represents switch1 and so on.
; //------------------------------------------------------------------------
; #include <m8c.h> // part specific constants and macros
; #include "PSoCAPI.h" // PSoC API definitions for all User Modules
;
; // bit masks defined for each button
; #define BUTTON_0 0x01
; #define BUTTON_1 0x02
; #define BUTTON_2 0x04
; #define BUTTON_3 0x08
; #define BUTTON_4 0x10
; #define BUTTON_5 0x20
; #define BUTTON_6 0x40
;
; // define the number of switches in this system
; #define NUM_SWITCHES 7
;
; // the followin defines the ranges for the raw counts
; // during the calibration routines
; #define DAC_MAX_RAW_COUNT 310
; #define DAC_MIN_RAW_COUNT 290
;
; // autocalibration routine
; //-----------------------------
; // will automatically determine the DAC settings for each switch in the system
; void CalibrateSwitches(void);
;
; // Array that holds the individual DAC settings for each switch
; BYTE bDACcurrent[NUM_SWITCHES];
;
; WORD i,x;
;
; // start main
; //------------------------------------------------------------------------------------------
; void main()
; {
.dbline 94
; CSR_1_Start(); // call CSR Start, does all the internal CSR connections
push X
xcall _CSR_1_Start
pop X
.dbline 95
; M8C_EnableGInt; // Enable global interrupts
or F, 01h
.dbline 96
; LCD_1_Start(); // Initialize LCD
push X
xcall _LCD_1_Start
pop X
.dbline 99
;
; // call the calibrate switches function to initialize the parameter settings
; CalibrateSwitches();
xcall _CalibrateSwitches
.dbline 101
;
; LCD_1_Start(); // Initialize LCD
push X
xcall _LCD_1_Start
.dbline 102
; LCD_1_Position(0,0);
mov A,0
mov X,A
xcall _LCD_1_Position
.dbline 103
; LCD_1_PrCString("7-Button ");
mov A,>L2
push A
mov A,<L2
mov X,A
pop A
xcall _LCD_1_PrCString
.dbline 104
; LCD_1_Position(1,0);
mov X,0
mov A,1
xcall _LCD_1_Position
.dbline 105
; LCD_1_PrCString("Demo v2.0 ");
mov A,>L3
push A
mov A,<L3
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 108
;
; // delay long enough for title and version to be displayed
; for (i=0; i< 60000; i++)
mov REG[0xd0],>_i
mov [_i+1],0
mov [_i],0
xjmp L7
L4:
.dbline 109
; {
.dbline 110
; for (x=0; x< 20; x++)
mov REG[0xd0],>_x
mov [_x+1],0
mov [_x],0
xjmp L11
L8:
.dbline 111
.dbline 111
L9:
.dbline 110
mov REG[0xd0],>_x
inc [_x+1]
adc [_x],0
L11:
.dbline 110
mov REG[0xd0],>_x
mov A,[_x+1]
sub A,20
mov A,[_x]
sbb A,0
jc L8
X1:
.dbline 112
L5:
.dbline 108
mov REG[0xd0],>_i
inc [_i+1]
adc [_i],0
L7:
.dbline 108
mov REG[0xd0],>_i
mov A,[_i+1]
mov REG[0xd0],>__r0
mov [__r3],A
mov REG[0xd0],>_i
mov A,[_i]
mov REG[0xd0],>__r0
mov [__r2],A
mov A,[__r3]
sub A,96
mov A,[__r2]
sbb A,-22
mov A,0
sbb A,0
mov A,0
xor A,-128
sbb A,(0 ^ 0x80)
jc L4
X2:
.dbline 114
; {}
; }
;
; LCD_1_Position(0,0);
push X
mov A,0
mov X,A
xcall _LCD_1_Position
.dbline 115
; LCD_1_PrCString(" ");
mov A,>L12
push A
mov A,<L12
mov X,A
pop A
xcall _LCD_1_PrCString
.dbline 116
; LCD_1_Position(1,0);
mov X,0
mov A,1
xcall _LCD_1_Position
.dbline 117
; LCD_1_PrCString(" ");
mov A,>L12
push A
mov A,<L12
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
xjmp L14
L13:
.dbline 120
;
; while(1) // start the main loop
; {
.dbline 122
; // scan each switch individually
; for (i=0; i<NUM_SWITCHES; i++)
mov REG[0xd0],>_i
mov [_i+1],0
mov [_i],0
xjmp L19
L16:
.dbline 123
; {
.dbline 124
; CSR_1_SetDacCurrent(bDACcurrent[i],0); // Sets DAC current
push X
mov A,0
push A
mov REG[0xd0],>_i
mov A,[_i+1]
add A,<_bDACcurrent
mov REG[0xd0],>__r0
mov [__r1],A
mov REG[0xd0],>_i
mov A,[_i]
adc A,>_bDACcurrent
mov REG[0xd0],>__r0
mov REG[0xd4],A
mvi A,[__r1]
pop X
xcall _CSR_1_SetDacCurrent
.dbline 125
; CSR_1_SetScanSpeed(3); // use a scanspeed of three (no overlay so buttons are very sensitive)
mov A,3
xcall _CSR_1_SetScanSpeed
.dbline 126
; CSR_1_StartScan(i,1,0); // Scan one Switch (i)
mov A,0
push A
mov A,1
push A
mov REG[0xd0],>_i
mov A,[_i+1]
mov REG[0xd0],>__r0
push A
xcall _CSR_1_StartScan
add SP,-3
pop X
L20:
.dbline 127
L21:
.dbline 127
push X
xcall _CSR_1_GetScanStatus
mov REG[0xd0],>__r0
pop X
mov [__r0],A
tst [__r0],32
jz L20
.dbline 128
L17:
.dbline 122
mov REG[0xd0],>_i
inc [_i+1]
adc [_i],0
L19:
.dbline 122
mov REG[0xd0],>_i
mov A,[_i+1]
sub A,7
mov A,[_i]
sbb A,0
jc L16
X3:
.dbline 139
; while(!(CSR_1_GetScanStatus() & CSR_1_SCAN_SET_COMPLETE)); // wait until the scan is complete
; }
;
; // call the update baseline function which does several functions, the two main
; // functions it provides are:
; // 1) updates each switches baseline (if necessary and according to the rate
; // set by the updateBaseline value
; // 2) determine the button status (on/off) and places this value
; // in CSR_1_baSwOnMask[]
; // if any of the buttons are determined to be "ON" then the function will
; // return a non-zero value
;
; if(CSR_1_bUpdateBaseline(0))
push X
mov A,0
xcall _CSR_1_bUpdateBaseline
pop X
cmp A,0
jz L23
.dbline 140
; {
.dbline 142
; // check to see if BUTTON 0 is on or off
; if ((CSR_1_baSwOnMask[0]) & BUTTON_0)
mov REG[0xd0],>_CSR_1_baSwOnMask
tst [_CSR_1_baSwOnMask],1
jz L25
.dbline 143
; {
.dbline 145
; // switch is ON
; LCD_1_Position(0,0);
push X
mov A,0
mov X,A
xcall _LCD_1_Position
.dbline 146
; LCD_1_PrCString("0 ");
mov A,>L27
push A
mov A,<L27
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 147
; }else
xjmp L26
L25:
.dbline 148
; {
.dbline 150
; // switch is OFF
; LCD_1_Position(0,0);
push X
mov A,0
mov X,A
xcall _LCD_1_Position
.dbline 151
; LCD_1_PrCString(" ");
mov A,>L28
push A
mov A,<L28
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 152
; }
L26:
.dbline 155
;
; // check to see if BUTTON 1 is on or off
; if ((CSR_1_baSwOnMask[0]) & BUTTON_1)
mov REG[0xd0],>_CSR_1_baSwOnMask
tst [_CSR_1_baSwOnMask],2
jz L29
.dbline 156
; {
.dbline 158
; // switch is ON
; LCD_1_Position(0,2);
push X
mov X,2
mov A,0
xcall _LCD_1_Position
.dbline 159
; LCD_1_PrCString("1 ");
mov A,>L31
push A
mov A,<L31
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 160
; }else
xjmp L30
L29:
.dbline 161
; {
.dbline 163
; // switch is OFF
; LCD_1_Position(0,2);
push X
mov X,2
mov A,0
xcall _LCD_1_Position
.dbline 164
; LCD_1_PrCString(" ");
mov A,>L28
push A
mov A,<L28
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 165
; }
L30:
.dbline 168
;
; // check to see if BUTTON 2 is on or off
; if ((CSR_1_baSwOnMask[0]) & BUTTON_2)
mov REG[0xd0],>_CSR_1_baSwOnMask
tst [_CSR_1_baSwOnMask],4
jz L32
.dbline 169
; {
.dbline 171
; // switch is ON
; LCD_1_Position(0,4);
push X
mov X,4
mov A,0
xcall _LCD_1_Position
.dbline 172
; LCD_1_PrCString("2 ");
mov A,>L34
push A
mov A,<L34
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 173
; }else
xjmp L33
L32:
.dbline 174
; {
.dbline 176
; // switch is OFF
; LCD_1_Position(0,4);
push X
mov X,4
mov A,0
xcall _LCD_1_Position
.dbline 177
; LCD_1_PrCString(" ");
mov A,>L28
push A
mov A,<L28
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 178
; }
L33:
.dbline 181
;
; // check to see if BUTTON 3 is on or off
; if ((CSR_1_baSwOnMask[0]) & BUTTON_3)
mov REG[0xd0],>_CSR_1_baSwOnMask
tst [_CSR_1_baSwOnMask],8
jz L35
.dbline 182
; {
.dbline 184
; // switch is ON
; LCD_1_Position(0,6);
push X
mov X,6
mov A,0
xcall _LCD_1_Position
.dbline 185
; LCD_1_PrCString("3 ");
mov A,>L37
push A
mov A,<L37
mov X,A
pop A
xcall _LCD_1_PrCString
pop X
.dbline 186
; }else
xjmp L36
L35:
.dbline 187
; {
.dbline 189
; // switch is OFF
; LCD_1_Position(0,6);
push X
mov X,6
mov A,0
xcall _LCD_1_Position
.dbline 190
; LCD_1_PrCString(" ");
mov A,>L28
push A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -