summaryrefslogtreecommitdiff
path: root/software/ttx_crx/ttx_crx.asm
blob: 066379f49ba02d3a6e576f6f08d0bfaabf19cf0a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
  ;;
  ;;  mur.sat
  ;;
  ;;  Somewhen in the year 2012, mur.at will have a nano satellite launched
  ;;  into a low earth orbit (310 km above the surface of our planet). The
  ;;  satellite itself is a TubeSat personal satellite kit, developed and
  ;;  launched by interorbital systems. mur.sat is a joint venture of mur.at,
  ;;  ESC im Labor and realraum.
  ;;
  ;;  Please visit the project hompage at sat.mur.at for further information.
  ;; 
  ;;
  ;;  Copyright (C) 2011 Christian Pointner <equinox@mur.at>
  ;;                         
  ;;  This file is part of mur.sat.
  ;;
  ;;  mur.sat is free software: you can redistribute it and/or modify
  ;;  it under the terms of the GNU General Public License as published by
  ;;  the Free Software Foundation, either version 3 of the License, or
  ;;  any later version.
  ;;
  ;;  mur.sat is distributed in the hope that it will be useful,
  ;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
  ;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ;;  GNU General Public License for more details.
  ;;
  ;;  You should have received a copy of the GNU General Public License
  ;;  along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
  ;;
  ;; -------------------------------------
  ;; PREAMBLE

  LIST      p=16F1847
  include   "p16f1847.inc"
  __config  _CONFIG1,  _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
  __config  _CONFIG2,  _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_LO & _LVP_OFF


  ;; -------------------------------------
  ;; DEFINES  
  ;;   constants
DOT_DEF       EQU .256 - .21      ; .29
DASH_DEF      EQU .256 - .63      ; .87
WSPACE_DEF    EQU .256 - .147     ; .203
TUNE_DEF      EQU DOT_DEF
BCNINTL_DEF   EQU .256 - .120
BCNINTH_DEF   EQU .255
START_CHAR    EQU 'N'
ACK_CHAR      EQU 'A'
OSC_LOW       EQU b'00010000'       ; 31,25 kHz
OSC_HIGH      EQU b'01101000'       ; 4 MHz
    

  ;;   I/O Pins
;; PortA
CW_ENABLE     EQU 2
CW_OUT        EQU 3
IHU_SS        EQU 5
IHU_SDO       EQU 6
IHU_INT       EQU 7  
;; PortB
CLK_1HZ       EQU 0
IHU_SDI       EQU 1
CRX_INT       EQU 3
IHU_SCK       EQU 4
I2C_SDA       EQU 6
I2C_SCL       EQU 7


  ;;   variables
;; page 0 only
ELEMENT     EQU H'0020'
ELECNT      EQU H'0021'
CHAR        EQU H'0022'
PARITY      EQU H'0023'
CHARCNT     EQU H'0024'
PENTLE0     EQU H'0025'
PENTLE1     EQU H'0026'
PENTLECNT   EQU H'0027'
ACK_DATA    EQU H'0028'
TMP1        EQU H'0029'
TMP2        EQU H'002A'
  
;; all pages
BEACON_INTL EQU H'0070'
BEACON_INTH EQU H'0071'
DOT         EQU H'0072'
ESPACE      EQU DOT
DASH        EQU H'0073'
CSPACE      EQU DASH
WSPACE      EQU H'0074'
TUNE        EQU H'0075'

I2C_BYTE    EQU H'0077'
I2C_BIT_CNT EQU H'0078'

NVSTATE     EQU H'007A'
BEACONCNTH  EQU H'007B'
BEACONCNTL  EQU H'007C'
STATE       EQU H'007D'
W_TEMP      EQU H'007E'
STATUS_TEMP EQU H'007F'

  ;; -------------------------------------
  ;; OFFSET
  org	      0
  goto      init

  ;; -------------------------------------
  ;; Interrupt Vector
  org	      .4
  ;; save context
  movwf     W_TEMP
  swapf     STATUS,W
  movwf     STATUS_TEMP

interrupt_end
  ;; restore context
  swapf     STATUS_TEMP,W
  movwf     STATUS
  swapf     W_TEMP,F
  swapf     W_TEMP,W
  retfie

  ;; -------------------------------------
  ;; TABLES
  include   "tables.inc"
  
  ;; -------------------------------------
  ;; SUBROUTINES

  ;; -------------------------------------
  include   "ttx.inc"

  ;; -------------------------------------
  include   "i2c.inc"

  ;; -------------------------------------
  ;; INIT
init
  ;; BANK 3
  movlb     .3
  clrf      ANSELA
  clrf      ANSELB

  ;; BANK 2
  movlb     .2
  movlw     b'01100000'
  movwf     APFCON0
  clrf      APFCON1
  
  ;; BANK 1
  movlb     .1
  movlw     b'00110011'
  movwf     TRISA
  movlw     b'11111111'
  movwf     TRISB
  movlw     OSC_LOW
  movwf     OSCCON
  movlw     b'01000011'
  movwf     OPTION_REG

  ;; BANK 0
  movlb     .0
  movlw     b'00000000'
  movwf     INTCON

  
  bcf       PORTA,CW_OUT
  bcf       PORTA,CW_ENABLE

  clrf      NVSTATE             ; TODO: read State from EEPROM
  movlw     .42
  movwf     BEACONCNTL          ; TODO: read Beaconcnt from EEPROM
  movlw     .23
  movwf     BEACONCNTH
  movlw     BCNINTL_DEF         ; TODO: read Beacon Interval from EEPROM
  movwf     BEACON_INTL
  movlw     BCNINTH_DEF
  movwf     BEACON_INTH

  movlw     DOT_DEF             ; TODO: read cw timings from EEPROM
  movwf     DOT                 ;   - DOT: length of .
  movlw     DASH_DEF            ;   - DASH: length of -
  movwf     DASH                ;   - WSPACE: length word space
  movlw     WSPACE_DEF          ;   - TUNE: tune in time of oscillator
  movwf     WSPACE
  movlw     TUNE_DEF
  movwf     TUNE

  ;; -------------------------------------
  ;; MAINLOOP
main
  clrw
  call      dottime

  call      send_beacon

  goto	    main

  ;; -------------------------------------
  ;; END
  end