Rev 410 | Blame | Compare with Previous | Last modification | View Log | Download
CCS PCW C Compiler, Version 3.110, 15448
Filename: d:\@kaklik\programy\pic_c\ps2mys\main.LST
ROM used: 273 (27%)
Largest free fragment is 751
RAM used: 9 (13%) at main() level
12 (18%) worst case
Stack: 1 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 0D1
0003: NOP
.................... #include "D:\@Kaklik\programy\PIC_C\PS2mys\main.h"
.................... #include <16F84.h>
.................... //////// Standard Header file for the PIC16F84 device ////////////////
.................... #device PIC16F84
.................... #list
....................
.................... #use delay(clock=4000000)
0004: MOVLW 16
0005: MOVWF 04
0006: MOVF 00,W
0007: BTFSC 03.2
0008: GOTO 018
0009: MOVLW 01
000A: MOVWF 0D
000B: CLRF 0C
000C: DECFSZ 0C,F
000D: GOTO 00C
000E: DECFSZ 0D,F
000F: GOTO 00B
0010: MOVLW 4A
0011: MOVWF 0C
0012: DECFSZ 0C,F
0013: GOTO 012
0014: NOP
0015: NOP
0016: DECFSZ 00,F
0017: GOTO 009
0018: GOTO 0DB (RETURN)
.................... #fuses XT,NOWDT
....................
.................... #DEFINE DATA PIN_B0 // musi byt definovan kanal DATA
.................... #DEFINE CLK PIN_B1 // a taky hodiny CLK
....................
.................... #define PRVNI 1000 // nastaveni prodlevy pred zacatkem vysilani bajtu
.................... #define DRUHY 2
.................... #define TRETI DRUHY
....................
.................... // prikazy
.................... #define RESET 0xFF
.................... #define ENABLE_DATA_REPORTING 0xF4
.................... #define READ_DATA 0xEB
.................... #define STATUS_REQUEST 0xE9
.................... #define SET_REMOTE_MODE 0xF0
.................... #define SET_STREAM_MODE 0xEA
.................... #define GET_DEVICE_ID 0xF2
....................
.................... #DEFINE LED_yellow PIN_A3
.................... #DEFINE LED_red PIN_A2
....................
.................... #DEFINE BLIK 120 // doba rozsviceni led
....................
.................... #include "PS2.c"
.................... // Modul pro komunikaci s Mysi
....................
.................... void send(byte command)
.................... {
.................... int n;
0019: CLRF 17
.................... int parity=0;
....................
.................... //Request-to-send
.................... output_float(DATA);
001A: BSF 03.5
001B: BSF 06.0
.................... output_low(CLK);
001C: BCF 06.1
001D: BCF 03.5
001E: BCF 06.1
.................... delay_us(100);
001F: MOVLW 21
0020: MOVWF 0C
0021: DECFSZ 0C,F
0022: GOTO 021
.................... // start bit
.................... output_low(DATA);
0023: BSF 03.5
0024: BCF 06.0
0025: BCF 03.5
0026: BCF 06.0
.................... delay_us(20);
0027: MOVLW 06
0028: MOVWF 0C
0029: DECFSZ 0C,F
002A: GOTO 029
002B: NOP
.................... while(!input(CLK));
002C: BSF 03.5
002D: BSF 06.1
002E: BCF 03.5
002F: BTFSS 06.1
0030: GOTO 02C
.................... // 8 bitu
.................... for(n=0; n<8; n++)
0031: CLRF 16
0032: MOVF 16,W
0033: SUBLW 07
0034: BTFSS 03.0
0035: GOTO 052
.................... {
.................... while(input(CLK));
0036: BSF 03.5
0037: BSF 06.1
0038: BCF 03.5
0039: BTFSC 06.1
003A: GOTO 036
.................... output_bit(DATA, command & 1);
003B: MOVF 15,W
003C: ANDLW 01
003D: XORLW 00
003E: BTFSS 03.2
003F: GOTO 042
0040: BCF 06.0
0041: GOTO 043
0042: BSF 06.0
0043: BSF 03.5
0044: BCF 06.0
.................... parity += command & 1;
0045: BCF 03.5
0046: MOVF 15,W
0047: ANDLW 01
0048: ADDWF 17,F
.................... command>>=1;
0049: BCF 03.0
004A: RRF 15,F
.................... while(!input(CLK));
004B: BSF 03.5
004C: BSF 06.1
004D: BCF 03.5
004E: BTFSS 06.1
004F: GOTO 04B
.................... };
0050: INCF 16,F
0051: GOTO 032
.................... // parita
.................... while(input(CLK));
0052: BSF 03.5
0053: BSF 06.1
0054: BCF 03.5
0055: BTFSC 06.1
0056: GOTO 052
.................... output_bit(DATA, ~parity & 1);
0057: MOVF 17,W
0058: XORLW FF
0059: ANDLW 01
005A: XORLW 00
005B: BTFSS 03.2
005C: GOTO 05F
005D: BCF 06.0
005E: GOTO 060
005F: BSF 06.0
0060: BSF 03.5
0061: BCF 06.0
.................... while(!input(CLK));
0062: BSF 06.1
0063: BCF 03.5
0064: BTFSC 06.1
0065: GOTO 068
0066: BSF 03.5
0067: GOTO 062
0068: GOTO 069
.................... // stop bit
.................... while(input(CLK));
0069: BSF 03.5
006A: BSF 06.1
006B: BCF 03.5
006C: BTFSC 06.1
006D: GOTO 069
.................... output_bit(DATA, 1);
006E: BSF 06.0
006F: BSF 03.5
0070: BCF 06.0
.................... while(!input(CLK));
0071: BSF 06.1
0072: BCF 03.5
0073: BTFSC 06.1
0074: GOTO 077
0075: BSF 03.5
0076: GOTO 071
0077: GOTO 078
.................... output_float(DATA);
0078: BSF 03.5
0079: BSF 06.0
007A: BCF 03.5
007B: GOTO 0E0 (RETURN)
.................... }
....................
....................
.................... int8 read_byte(int8 const poradi)
.................... {
.................... int8 bajt;
.................... int8 i;
....................
.................... // cekani na komunikacni klid
.................... for (i=0; i<poradi; i++)
007C: CLRF 16
007D: SUBWF 16,W
007E: BTFSC 03.0
007F: GOTO 08D
.................... {
.................... if (!input(CLK) || !input(DATA)) i=0;
0080: BSF 03.5
0081: BSF 06.1
0082: BCF 03.5
0083: BTFSS 06.1
0084: GOTO 08A
0085: BSF 03.5
0086: BSF 06.0
0087: BCF 03.5
0088: BTFSC 06.0
0089: GOTO 08B
008A: CLRF 16
.................... };
008B: INCF 16,F
008C: GOTO 07D
....................
.................... // cekani na startbit
.................... while(input(CLK) || input(DATA));
008D: BSF 03.5
008E: BSF 06.1
008F: BCF 03.5
0090: BTFSC 06.1
0091: GOTO 08D
0092: BSF 03.5
0093: BSF 06.0
0094: BCF 03.5
0095: BTFSC 06.0
0096: GOTO 08D
.................... while(!input(CLK));
0097: BSF 03.5
0098: BSF 06.1
0099: BCF 03.5
009A: BTFSS 06.1
009B: GOTO 097
....................
.................... bajt = 0;
009C: CLRF 15
.................... for(i=0; i<8; i++)
009D: CLRF 16
009E: MOVF 16,W
009F: SUBLW 07
00A0: BTFSS 03.0
00A1: GOTO 0BD
.................... {
.................... while(input(CLK)); // ceka na nulu hodin
00A2: BSF 03.5
00A3: BSF 06.1
00A4: BCF 03.5
00A5: BTFSC 06.1
00A6: GOTO 0A2
....................
.................... bajt >>= 1;
00A7: BCF 03.0
00A8: RRF 15,F
.................... bajt |= input(DATA) << 7;
00A9: BSF 03.5
00AA: BSF 06.0
00AB: MOVLW 00
00AC: BCF 03.5
00AD: BTFSC 06.0
00AE: MOVLW 01
00AF: MOVWF 0C
00B0: RRF 0C,W
00B1: CLRF 0C
00B2: BTFSC 03.0
00B3: BSF 0C.7
00B4: MOVF 0C,W
00B5: IORWF 15,F
....................
.................... while(!input(CLK)); // ceka na jednicku hodin
00B6: BSF 03.5
00B7: BSF 06.1
00B8: BCF 03.5
00B9: BTFSS 06.1
00BA: GOTO 0B6
.................... };
00BB: INCF 16,F
00BC: GOTO 09E
.................... return (bajt);
00BD: MOVF 15,W
00BE: MOVWF 0D
00BF: RETLW 00
.................... }
....................
....................
.................... /*void read_all_byte(int8*st,*nd,*rd) // precte 3 bajty
.................... {
.................... int8 i;
....................
.................... // *st=read_byte(1st);
....................
.................... // cekani na startbit
.................... while(input(CLK) || input(DATA));
.................... while(!input(CLK));
.................... *nd = 0;
.................... for(i=0; i<8; i++)
.................... {
.................... while(input(CLK)); // ceka na nulu hodin
....................
.................... *nd |= input(DATA) << 7;
.................... *nd >>= 1;
....................
.................... while(!input(CLK)); // ceka na jednicku hodin
.................... };
....................
.................... // cekani na startbit
.................... while(input(CLK) || input(DATA));
.................... while(!input(CLK));
.................... *rd = 0;
.................... for(i=0; i<8; i++)
.................... {
.................... while(input(CLK)); // ceka na nulu hodin
....................
.................... *rd |= input(DATA) << 7;
.................... *rd >>= 1;
....................
.................... while(!input(CLK)); // ceka na jednicku hodin
.................... };
.................... }*/
....................
....................
.................... #define SIGN_X 4
....................
.................... void trigger()
.................... {
.................... output_high(PIN_A0);
00C0: BSF 03.5
00C1: BCF 05.0
00C2: BCF 03.5
00C3: BSF 05.0
.................... output_low(PIN_A0);
00C4: BSF 03.5
00C5: BCF 05.0
00C6: BCF 03.5
00C7: BCF 05.0
.................... delay_us(100);
00C8: MOVLW 21
00C9: MOVWF 0C
00CA: DECFSZ 0C,F
00CB: GOTO 0CA
.................... output_high(PIN_A0);
00CC: BSF 03.5
00CD: BCF 05.0
00CE: BCF 03.5
00CF: BSF 05.0
00D0: GOTO 0FC (RETURN)
.................... }
....................
.................... void flash_red() // blikne ledkou
.................... {
.................... output_high(LED_red);
.................... Delay_ms(BLIK);
.................... output_low(LED_red);
.................... }
....................
.................... void flash_yellow() // blikne ledkou
.................... {
.................... output_high(LED_yellow);
.................... Delay_ms(BLIK);
.................... output_low(LED_yellow);
.................... }
....................
.................... void main()
.................... {
.................... int8 X,y,tl=0;
*
00D4: CLRF 11
00D5: CLRF 14
.................... int8 X_old,y_old,tl_old=0;
*
00D1: CLRF 04
00D2: MOVLW 1F
00D3: ANDWF 03,F
....................
.................... Delay_ms(500);
*
00D6: MOVLW 02
00D7: MOVWF 15
00D8: MOVLW FA
00D9: MOVWF 16
00DA: GOTO 004
00DB: DECFSZ 15,F
00DC: GOTO 0D8
.................... send(ENABLE_DATA_REPORTING);
00DD: MOVLW F4
00DE: MOVWF 15
00DF: GOTO 019
....................
.................... while(true)
.................... {
.................... tl = read_byte(PRVNI);
00E0: MOVLW E8
00E1: BSF 03.5
00E2: BSF 03.6
00E3: MOVWF 7F
00E4: BCF 03.5
00E5: BCF 03.6
00E6: CALL 07C
00E7: MOVF 0D,W
00E8: MOVWF 11
.................... x = read_byte(DRUHY);
00E9: MOVLW 02
00EA: BSF 03.5
00EB: BSF 03.6
00EC: MOVWF 7F
00ED: BCF 03.5
00EE: BCF 03.6
00EF: CALL 07C
00F0: MOVF 0D,W
00F1: MOVWF 0F
.................... y = read_byte(TRETI);
00F2: MOVLW 02
00F3: BSF 03.5
00F4: BSF 03.6
00F5: MOVWF 7F
00F6: BCF 03.5
00F7: BCF 03.6
00F8: CALL 07C
00F9: MOVF 0D,W
00FA: MOVWF 10
.................... trigger();
00FB: GOTO 0C0
....................
....................
.................... if (bit_test(tl, SIGN_X))
00FC: BTFSS 11.4
00FD: GOTO 107
.................... {
.................... output_high(LED_red);
00FE: BSF 03.5
00FF: BCF 05.2
0100: BCF 03.5
0101: BSF 05.2
.................... output_low(LED_yellow);
0102: BSF 03.5
0103: BCF 05.3
0104: BCF 03.5
0105: BCF 05.3
.................... }
.................... else
0106: GOTO 10F
.................... {
.................... output_high(LED_yellow);
0107: BSF 03.5
0108: BCF 05.3
0109: BCF 03.5
010A: BSF 05.3
.................... output_low(LED_red);
010B: BSF 03.5
010C: BCF 05.2
010D: BCF 03.5
010E: BCF 05.2
.................... }
.................... }
010F: GOTO 0E0
.................... }
....................
0110: SLEEP
....................
....................