PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/MSP-EXP430FR5969/MSP-EXP430FR5969_8MHz_SD_Card/RC5toLCD.4th

https://gitlab.com/Jean-Michel/FastForthForMSP430fr5xxx
Forth | 489 lines | 446 code | 43 blank | 0 comment | 17 complexity | 64e3a45f12b2e42e374673e2605676b0 MD5 | raw file
Possible License(s): GPL-3.0
  1. ; ----------------------------------
  2. ; MSP-EXP430FR5969_8MHZ_RC5toLCD.4th
  3. ; ----------------------------------
  4. STOP ; to stop any interrupt in progress
  5. WIPE ;
  6. NOECHO ; comment to debug
  7. ; Copyright (C) <2015> <J.M. THOORENS>
  8. ;
  9. ; This program is free software: you can redistribute it and/or modify
  10. ; it under the terms of the GNU General Public License as published by
  11. ; the Free Software Foundation, either version 3 of the License, or
  12. ; (at your option) any later version.
  13. ;
  14. ; This program is distributed in the hope that it will be useful,
  15. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ; GNU General Public License for more details.
  18. ;
  19. ; You should have received a copy of the GNU General Public License
  20. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. ; display on a LCD 2x20 CHAR the code sent by an IR remote under philips RC5 protocol
  22. ; target : MSP-EXP430fr5969 LAUNCHPAD at 8 MHz
  23. ; DEMO : driver for IR remote compatible with the PHILIPS RC5 protocol
  24. ; plus : driver for 5V LCD 2x20 characters display with 4 bits data interface
  25. ; without usage of an auxiliary 5V to feed the LCD_Vo
  26. ; without potentiometer to adjust the LCD contrast :
  27. ; to adjust LCD contrast, just press S1 (-) or S2 (+)
  28. ; P2.2 current consumption ~ 500 uA
  29. ; ===================================================================================
  30. ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
  31. ; ===================================================================================
  32. ; -----------------------------------------------
  33. ; MSP - LAUNCHPAD <--> OUTPUT WORLD
  34. ; -----------------------------------------------
  35. ; P4.6 - J6 - LED1 red
  36. ; P1.0 - LED2 green
  37. ; P4.5 - Switch S1 <--- LCD contrast + (finger :-)
  38. ; P1.1 - Switch S2 <--- LCD contrast - (finger ;-)
  39. ; GND - J1.2 <-------+---0V0----------> 1 LCD_Vss
  40. ; VCC - J1.3 >------ | --3V6-----+----> 2 LCD_Vdd
  41. ; | |
  42. ; |___ 470n ---
  43. ; ^ | ---
  44. ; / \ BAT54 |
  45. ; --- |
  46. ; 100n | 2k2 |
  47. ; P2.2 - J4.7 UCB0 CLK TB0.2 >---||--+--^/\/\/v--+----> 3 LCD_Vo (=0V6 without modulation)
  48. ; P3.4 - J4.8 -------------------------> 4 LCD_RS
  49. ; P3.5 - J4.9 -------------------------> 5 LCD_R/W
  50. ; P3.6 - J4.10 -------------------------> 6 LCD_EN0
  51. ; PJ.0 - J3.1 <------------------------> 11 LCD_DB4
  52. ; PJ.1 - J3.3 <------------------------> 12 LCD_DB5
  53. ; PJ.2 - J3.5 <------------------------> 13 LCD_DB5
  54. ; PJ.3 - J3.7 <------------------------> 14 LCD_DB7
  55. ; PJ.4 - LFXI 32768Hz quartz
  56. ; PJ.5 - LFXO 32768Hz quartz
  57. ; PJ.6 - HFXI
  58. ; PJ.7 - HFXO
  59. ; P2.0 - J13.8 UCA0 TXD ---> RX UARTtoUSB bridge
  60. ; P2.1 - J13.10 UCA0 RXD <--- TX UARTtoUSB bridge
  61. ; P4.1 - J13.14 RTS ---> CTS UARTtoUSB bridge (optional hardware control flow)
  62. ; VCC - J13.16 <--- VCC (optional supply from UARTtoUSB bridge - WARNING ! 3.3V !)
  63. ; GND - J13.20 <--> GND (optional supply from UARTtoUSB bridge)
  64. ; VCC - J11.1 ---> VCC SD_CardAdapter
  65. ; GND - J12.3 <--> GND SD_CardAdapter
  66. ; P2.4 - J4.6 UCA1 CLK ---> CLK SD_CardAdapter (SCK)
  67. ; P4.3 - J4.5 ---> CS SD_CardAdapter (Card Select)
  68. ; P2.5 - J4.4 UCA1 TXD/SIMO ---> SDI SD_CardAdapter (MOSI)
  69. ; P2.6 - J4.3 UCA1 RXD/SOMI <--- SDO SD_CardAdapter (MISO)
  70. ; P4.2 - J4.2 <--- CD SD_CardAdapter (Card Detect)
  71. ; P4.0 - J3.10 CTS <--- OUT IR_Receiver (1 TSOP32236)
  72. ; VCC - J3.2 ---> VCC IR_Receiver (2 TSOP32236)
  73. ; GND - J3.9 <--> GND IR_Receiver (3 TSOP32236)
  74. ; P1.2 - J5.19 <--> SDA I2C SOFTWARE MASTER
  75. ; P1.3 - J5.11 <--> SCL I2C SOFTWARE MASTER
  76. ; P1.4 - J5.12 TB0.1 <--> free
  77. ; P1.5 - J5.13 UCA0 CLK TB0.2 <--> free
  78. ; P1.7 - J5.14 UCB0 SCL/SOMI <--> SCL I2C MASTER/SLAVE
  79. ; P1.6 - J5.15 UCB0 SDA/SIMO <--> SDA I2C MASTER/SLAVE
  80. ; P3.0 - J5.7 <--- free
  81. ; P2.3 - NC
  82. ; P2.7 - NC
  83. ; P3.1 - NC
  84. ; P3.2 - NC
  85. ; P3.3 - NC
  86. ; P3.7 - NC
  87. ; P4.4 - NC
  88. ; P4.7 - NC
  89. ; HERE ; general minidump, part 1
  90. ; ------------------------------;
  91. CODE 20_us ; n -- n * 20 us
  92. ; ------------------------------;
  93. BEGIN ; 3 cycles loop + 6~
  94. ; MOV #5,W ; 3 MCLK = 1 MHz
  95. ; MOV #23,W ; 3 MCLK = 4 MHz
  96. MOV #51,W ; 3 MCLK = 8 MHz
  97. ; MOV #104,W ; 3 MCLK = 16 MHz
  98. ; MOV #158,W ; 3 MCLK = 24 MHz
  99. BEGIN ; 3 cycles loop ==> 3 * W / F us = 100 us - 1 @ 8 MHz
  100. SUB #1,W ; 1
  101. 0= UNTIL ; 2
  102. SUB #1,TOS ; 1
  103. 0= UNTIL ; 2
  104. MOV @PSP+,TOS ; 2
  105. MOV @IP+,PC ; 4
  106. ENDCODE
  107. ; ------------------------------;
  108. CODE TOP_LCD ; LCD Sample
  109. ; ------------------------------; if write : 0bxxxxWWWW --
  110. ; if read : -- 0b0000RRRR
  111. BIS.B #0x40,&0x222 ; P3OUT.6 LCD_EN 0-->1
  112. BIT.B #0x20,&0x220 ; P3IN.5 LCD_RW test
  113. 0= IF ; write LCD bits pattern
  114. AND #0x0F,TOS ;
  115. MOV.B TOS, &0x322 ; MOVE LCD_Data bits to PJ(0-3)
  116. BIC.B #0x40,&0x222 ; P3OUT.6 LCD_EN 1-->0 ==> strobe data
  117. MOV @PSP+,TOS ;
  118. MOV @IP+,PC
  119. THEN ; read LCD bits pattern
  120. SUB #2,PSP
  121. MOV TOS,0(PSP)
  122. BIC.B #0x40,&0x222 ; P3OUT.6 LCD_EN 1-->0 ==> strobe data
  123. MOV.B &0x320,TOS ; get LCD_Data from PJ(0-3)
  124. AND.B #0x0F,TOS
  125. MOV @IP+,PC
  126. ENDCODE
  127. ; ------------------------------;
  128. CODE LCD_W ; byte -- write byte
  129. ; ------------------------------;
  130. SUB #2,PSP ;
  131. MOV TOS,0(PSP) ; -- 0bxxxxLLLL 0bHHHHLLLL
  132. RRUM #4,TOS ; -- 0bxxxxLLLL 0bxxxxHHHH
  133. BIC.B #0x20,&0x222 ; P3OUT.5 LCD_RW=0
  134. BIS.B #0x0F,&0x324 ; PJDIR.(0-3) LCD_Data as output
  135. PUSH IP
  136. ASM>FORTH
  137. TOP_LCD 2 20_us \ write high nibble first
  138. TOP_LCD 2 20_us ;
  139. ; ------------------------------;
  140. CODE LCD_R ; -- byte read byte
  141. ; ------------------------------;
  142. BIC.B #0x0F,&0x324 ; PJ.(0-3) LCD_Data as intput
  143. BIS.B #0x20,&0x222 ; P3.5 LCD_RW=1
  144. PUSH IP
  145. ASM>FORTH
  146. TOP_LCD 2 20_us \ read high nibble first
  147. TOP_LCD 2 20_us
  148. FORTH>ASM ; -- 0b0000HHHH 0b0000LLLL
  149. MOV @RSP+,IP
  150. MOV @PSP+,W ; W = high nibble
  151. RLAM #4,W ; -- 0b0000LLLL W = 0bHHHH0000
  152. ADD.B W,TOS
  153. MOV @IP+,PC
  154. ENDCODE
  155. ; ------------------------------;
  156. CODE LCD_WrF ; func -- Write Fonction
  157. ; ------------------------------;
  158. BIC.B #0x10,&0x222 ; P3OUT.4 LCD_RS=0
  159. JMP LCD_W
  160. ENDCODE
  161. ; ------------------------------;
  162. CODE LCD_RdS ; -- status Read Status
  163. ; ------------------------------;
  164. BIC.B #0x10,&0x222 ; P3OUT.4 LCD_RS=0
  165. JMP LCD_R
  166. ENDCODE
  167. ; ------------------------------;
  168. CODE LCD_WrC ; char -- Write Char
  169. ; ------------------------------;
  170. BIS.B #0x10,&0x222 ; P3OUT.4 LCD_RS=1
  171. JMP LCD_W
  172. ENDCODE
  173. ; ------------------------------;
  174. CODE LCD_RdC ; -- char Read Char
  175. ; ------------------------------;
  176. BIS.B #0x10,&0x222 ; P3OUT.4 LCD_RS=1
  177. JMP LCD_R
  178. ENDCODE
  179. ; ------------------------------;
  180. \ : LCD_Clear 0x01 LCD_WrF 80 20_us ; bad init !
  181. : LCD_Clear 0x01 LCD_WrF 100 20_us ;
  182. ; ------------------------------;
  183. : LCD_Home 0x02 LCD_WrF 80 20_us ;
  184. ; ------------------------------;
  185. ; : LCD_Entry_set 0x04 OR LCD_WrF ;
  186. ; : LCD_Display_Ctrl 0x08 OR LCD_WrF ;
  187. ; : LCD_Display_Shift 0x10 OR LCD_WrF ;
  188. ; : LCD_Fn_Set 0x20 OR LCD_WrF ;
  189. ; : LCD_CGRAM_Set 0x40 OR LCD_WrF ;
  190. ; : LCD_Goto 0x80 OR LCD_WrF ;
  191. ; ------------------------------;
  192. ; IR_RC5 driver ;
  193. ; ******************************;
  194. CODE IR_RC5 ; wake up on P4.0 change interrupt
  195. ; ******************************;
  196. BIC #0xF8,0(RSP) ; CPU on, GIE off in oldSR
  197. ; ------------------------------;
  198. ; in : SR(9)=old Toggle bit memory
  199. ; SMclock = 8 MHz or 16 MHz
  200. ; use : U,V,W,X,Y, TA0 timer, TA0R register
  201. ; out : U = 0 x T A4 A3 A2 A1 A0| 0 C6 C5 C4 C3 C2 C1 C0
  202. ; SR(9)=new Toggle bit memory
  203. ; ------------------------------;
  204. ; RC5_FirstStartBitHalfCycle: ;
  205. ; ------------------------------;
  206. MOV #0,&0x0360 ; predivide by 1 in TA0EX0 register ( 8 MHZ), reset value
  207. ; MOV #1,&0x0360 ; predivide by 2 in TA0EX0 register (16 MHZ)
  208. ; MOV #2,&0x0360 ; predivide by 3 in TA0EX0 register (24 MHZ)
  209. MOV #1778,X ; RC5_Period in us
  210. MOV #14,W ; count of loop
  211. BEGIN ;
  212. ; ------------------------------;
  213. ; RC5_TopSynchro: ; <--- loop back ---+ with readjusted RC5_Period
  214. ; ------------------------------; | here, we are just after 1/2 RC5_cycle
  215. MOV #0b1011100100,&0x0340 ; (re)start timer_A | SMCLK_pre/2 /8 : 2us time interval,free running,clear TA0_IFG and TA0R
  216. ; RC5_Compute_3_4Period: ; |
  217. RRUM #1,X ; X=1/2 cycle |
  218. MOV X,Y ; Y=1/2 ^
  219. RRUM #1,Y ; Y=1/4
  220. ADD X,Y ; Y=3/4
  221. ; RC5_Wait_1_4: ; wait 3/4 cycle after 1/2 cycle to sample RC5_Input at 1/4 cycle
  222. BEGIN CMP Y,&0x0350 ; CMP &TA0R with 3/4 cycle value
  223. = UNTIL ;
  224. ; ------------------------------;
  225. ; RC5_Sample: ; at 1/4 cycle, we can sample RC5_input, ST2/C6 bit first
  226. ; ------------------------------;
  227. BIT.B #0x01,&0x0221 ; C_flag = P4.0 = IR bit
  228. ADDC V,V ; C_flag <-- V(15):V(0) <-- C_flag
  229. MOV.B &0x0221,&0x0239 ; preset IES_4.0 state for next IFG
  230. BIC.B #0x01,&0x023D ; clear P4.0_IFG after full cycle pin change
  231. SUB #1,W ; decrement count loop
  232. ; count = 13 ==> V = x x x x x x x x |x x x x x x x /C6
  233. ; count = 0 ==> V = x x /C6 Tg A4 A3 A2 A1|A0 C5 C4 C3 C2 C1 C0 1
  234. 0<> WHILE ; ----> out of loop ----+
  235. ; RC5_compute_2_4_OverFlow: ; |
  236. ADD X,Y ; | out of bound = 5/4 period
  237. ; RC5_WaitHalfCycleP1.2_IFG: ; |
  238. BEGIN ; |
  239. CMP Y,&0x0350 ; | TA0R = 5/4 cycle test
  240. >= IF ; | if cycle time out of bound
  241. MOV #4,&0x0340 ; | stop timer_A and clear TA0R
  242. RETI ; | then quit to do nothing
  243. THEN ; |
  244. ; ------------------------------; |
  245. BIT.B #0x01,&0x023D ; ^ | test P4.0_IFG
  246. <> UNTIL ; | |
  247. MOV &0x0350,X ; | | get new RC5_period value
  248. REPEAT ; ----> loop back --+ |
  249. ; ------------------------------; |
  250. ; RC5_SampleEndOf: ; <---------------------+
  251. ; ------------------------------;
  252. MOV #4,&0x0340 ; stop timer_A
  253. RLAM #1,V ; V = x /C6 Tg A4 A3 A2 A1 A0|C5 C4 C3 C2 C1 C0 1 0
  254. ; ------------------------------;
  255. ; ------------------------------;
  256. ; Only New_RC5_Command ADD_ON ; use SR(9) bit as toggle bit
  257. ; ------------------------------;
  258. MOV @RSP,X ; retiSR(9) = old RC5 toggle bit
  259. RLAM #4,X ; retiSR(9) --> X(13)
  260. XOR V,X ; (new XOR old)(13) Toggle bit
  261. BIT #0x2000,X ; X(13) = New_RC5_command
  262. 0= IF ;
  263. RETI ; case of repeated RC5_command : RETI without SR(9) change
  264. THEN ;
  265. XOR #0x0200,0(RSP) ; change Toggle bit memory SR(9)
  266. ; ------------------------------;
  267. ; ------------------------------;
  268. ; RC5_ComputeNewRC5word ;
  269. ; ------------------------------;
  270. MOV.B V,U ; U= 0 0 0 0 0 0 0 0 C5 C4 C3 C2 C1 C0 0 0
  271. RRUM #2,U ; U= 0 0 0 0 0 0 0 0 0 0 C5 C4 C3 C2 C1 C0
  272. ; AND #0x7F00,V ; V= 0 /C6 Tg A4 A3 A2 A1 A0 0 0 0 0 0 0 0 0
  273. ; ADD V,U ; U= 0 /C6 Tg A4 A3 A2 A1 A0 0 0 C5 C4 C3 C2 C1 C0
  274. ; ------------------------------;
  275. ; RC5_ComputeC6bit ;
  276. ; ------------------------------;
  277. BIT #0x4000,V ; test /C6
  278. 0= IF BIS.B #0x40,U ; set C6 bit
  279. THEN ;
  280. ; ------------------------------;
  281. ; RC5_CommandByteIsDone: ; U= 0 0 0 0 0 0 0 0 0 C6 C5 C4 C3 C2 C1 C0
  282. ; ------------------------------;
  283. ; ------------------------------;
  284. ; Display IR_RC5 code ;
  285. ; ------------------------------;
  286. BIS.B #0x40,&0x0223 ; P4.6 OUT high ==> switch ON LED1
  287. ; ------------------------------;
  288. SUB #4,PSP ;
  289. MOV &BASE,2(PSP) ; save base
  290. MOV TOS,0(PSP) ;
  291. MOV.B U,TOS ;
  292. ASM>FORTH \ ; IP is free
  293. ['] LCD_CLEAR IS CR
  294. ['] LCD_WrC IS EMIT
  295. CR ." 0x" HEX 2 U.R
  296. ['] (CR) IS CR
  297. ['] (EMIT) IS EMIT
  298. FORTH>ASM ; nice code, right ?
  299. MOV @PSP+,&BASE
  300. ; ------------------------------;
  301. BIC.B #0x40,&0x0223 ; P4.6 OUT low ==> switch OFF LED1
  302. ; ------------------------------;
  303. RETI ; CPU is ON, GIE is OFF
  304. ENDCODE ;
  305. ; ******************************;
  306. ; ******************************;
  307. CODE WDT_Int ; Watchdog interrupt routine, warning : not FORTH executable !
  308. ; ******************************;
  309. BIC #0xF8,0(RSP) ; set CPU ON and GIE OFF in retiSR
  310. ; ******************************;
  311. BIT.B #0x02,&0x200 ; test P1IN.1 = switch S2
  312. 0= IF ; case of switch S2 pressed
  313. CMP #34,&0x3D6 ; TB0CCR2 ; maxi Ton = 34/40 & VDD=3V6 ==> LCD_Vo = -2V2
  314. U< IF
  315. ADD #1,&0x3D6 ; TB0CCR2 ; action for switch S2 (P1.1) : 78 mV / increment
  316. THEN
  317. ELSE
  318. BIT.B #0x20,&0x221 ; test P4IN.5 = switch S1 input
  319. 0= IF ; case of Switch S1 pressed
  320. CMP #7,&0x3D6 ; TB0CCR2 ; mini Ton = 6/40 & VDD=3V6 ==> LCD_Vo = 0V
  321. U>= IF ;
  322. SUB #1,&0x3D6 ; TB0CCR2 ; action for switch S1 (P4.5) : -78 mV / decrement
  323. THEN ;
  324. THEN ;
  325. THEN ;
  326. RETI ; CPU is ON, GIE is OFF
  327. ENDCODE ;
  328. ; ******************************;
  329. ; ------------------------------;
  330. CODE START ; init application
  331. ; ------------------------------;
  332. ; 0b0000 0010 1001 0100 ; TB0CTL = 0x3C0
  333. ; - - ; CNTL Counter lentgh ; 00 = 16 bits
  334. ; -- ; TBSSEL TimerB clock select ; 10 = SMCLK
  335. ; -- ; ID input divider ; 10 = /4
  336. ; -- ; MC Mode Control ; 01 = up mode
  337. ; - ; TBCLR TimerB Clear
  338. ; - ; TBIE
  339. ; - ; TBIFG
  340. ; ------------------------------;
  341. ; 0b0000 0000 0110 0000 ; TB0CCTLx = 0x3C{2,4,6,8,A,C,E}
  342. ; -- ; CM Capture Mode
  343. ; -- ; CCIS
  344. ; - ; SCS
  345. ; -- ; CLLD
  346. ; - ; CAP
  347. ; --- ; OUTMOD ; 011 = set/reset
  348. ; - ; CCIE
  349. ; - ; CCI
  350. ; - ; OUT
  351. ; - ; COV
  352. ; - ; CCIFG
  353. ; ------------------------------;
  354. ; ; TB0CCRx 0x3D{2,4,6,8,A,C,E}
  355. ; ; TB0EX0 0x3E0
  356. ; ------------------------------;
  357. ; set TimerB to make 50kHz PWM ;
  358. ; ------------------------------;
  359. ; MOV #0b1000010100,&0x3C0 ; TB0CTL = SMCLK/1, up mode, clear timer, no int
  360. ; MOV #0,&0x03E0 ; predivide by 1 in TB0EX0 register (1 MHZ) (25 kHz PWM)
  361. ; ------------------------------;
  362. ; MOV #0b1000010100,&0x3C0 ; TB0CTL = SMCLK/1, up mode, clear timer, no int
  363. ; MOV #1,&0x03E0 ; predivide by 2 in TB0EX0 register (4 MHZ)
  364. ; ------------------------------;
  365. MOV #0b1010010100,&0x3C0 ; TB0CTL = SMCLK/4, up mode, clear timer, no int
  366. MOV #0,&0x03E0 ; predivide by 1 in TB0EX0 register (8 MHZ)
  367. ; ------------------------------;
  368. ; MOV #0b1010010100,&0x3C0 ; TB0CTL = SMCLK/4, up mode, clear timer, no int
  369. ; MOV #1,&0x03E0 ; predivide by 2 in TB0EX0 register (16 MHZ)
  370. ; ------------------------------;
  371. ; MOV #0b1010010100,&0x3C0 ; TB0CTL = SMCLK/4, up mode, clear timer, no int
  372. ; MOV #2,&0x03E0 ; predivide by 3 in TB0EX0 register (24 MHZ)
  373. ; ------------------------------;
  374. MOV #40,&0x3D2 ; TB0CCR0 = 40*0.5us=20us (40us @ 1MHz)
  375. ; ------------------------------;
  376. ; set TimerB to generate LCD_V0 via TB0.2 and P1.5/P2.2
  377. ; ------------------------------;
  378. MOV #0b1100000,&0x3C6 ; TB0CCTL2 output mode = set/reset ; clear CCIFG
  379. MOV #20,&0x3D6 ; TB0CCR2 ; contrast adjust : 20/40 ==> LCD_Vo = -1V1
  380. ; ------------------------------;
  381. ; init PORTA (P2:P1) (complement)
  382. BIS.B #0x04,&0x205 ; P2DIR.2 TB0.2 output
  383. BIS.B #0x04,&0x20B ; P2SEL0.2 TB0.2
  384. ; ------------------------------;
  385. ; init PORTB (P4:P3) (complement)
  386. BIS.B #0x70,&0x224 ; P3DIR.(4-6) as outputs
  387. BIC.B #0x70,&0x226 ; P3REN.(4-6) pullup/down disable
  388. BIC.B #0x30,&0x222 ; P3OUT.5 LCD_RW=0, P3OUT.4 LCD_RS=0
  389. BIS.B #1,&0x239 ; P4IES.0 high to low edge select
  390. BIC.B #1,&0x23D ; P4IFG.0 clear int flag TSOP32236 (after IES select)
  391. BIS.B #1,&0x23B ; P4IE.0 enable interrupt TSOP32236
  392. ; ------------------------------;
  393. ; init PORTJ (PJ) (complement)
  394. BIS.B #0x0F,&0x324 ; PJDIR.(0-3) as output, wired to DB(4-7) LCD_Data
  395. BIC.B #0x0F,&0x326 ; PJREN.(0-3) LCD_Data pullup/down disable
  396. ; ------------------------------;
  397. ; WDT interval init part ;
  398. ; ------------------------------;
  399. ; MOV #0x5A5E,&0x15C ; init WDT Vloclk source 10kHz /2^9 (50 ms), interval mode
  400. MOV #0x5A3D,&0x15C ; init WDT ACLK source 32.768kHz /2^13 (250 ms), interval mode
  401. ; MOV #0x5A5D,&0x15C ; init WDT Vloclk source 10kHz /2^13 (800 ms), interval mode
  402. BIS #1,&0x100 ; enable WDT interval mode interrupt in SFRIE
  403. ; ------------------------------;
  404. ; init interrupt vectors
  405. ; ------------------------------;
  406. MOV #WDT_Int,&0xFFF2 ; init WDT interval vector interrupt
  407. MOV #IR_RC5,&0xFFD0 ; init P4 interrupt vector
  408. ; ------------------------------;
  409. ; Init LCD 2x20 ;
  410. ; ------------------------------;
  411. ASM>FORTH
  412. 0x03E8 20_us \ ; 1- wait 20 ms
  413. 0x03 TOP_LCD \ ; 2- send DB5=DB4=1
  414. 0xCD 20_us \ ; 3- wait 4,1 ms
  415. 0x03 TOP_LCD \ ; 4- send again DB5=DB4=1
  416. 5 20_us \ ; 5- wait 0,1 ms
  417. 0x03 TOP_LCD \ ; 6- send again again DB5=DB4=1
  418. 2 20_us \ ; wait 40 us = LCD cycle
  419. 0x02 TOP_LCD \ ; 7- send DB5=1 DB4=0
  420. 2 20_us \ ; wait 40 us = LCD cycle
  421. 0x28 LCD_WrF \ ; 8- 0b001DNFxx "FonctionSet" D=8/4 DataBus width, Number of lines=2/1, Font bold/normal
  422. 0x08 LCD_WrF \ ; 9- 0b1DCB "DisplayControl" : Display off, Cursor off, Blink off.
  423. LCD_Clear \ ; 10- "LCD_Clear"
  424. 0x06 LCD_WrF \ ; 11- 0b01xx "LCD_EntrySet" : address and cursor shift after writing in RAM
  425. 0x0C LCD_WrF \ ; 12- 0b1DCB "DisplayControl" : Display on, Cursor off, Blink off.
  426. ." RC5toLCD is running. Type STOP to quit"
  427. LIT RECURSE IS WARM \ ; insert this starting routine between COLD and (WARM)...
  428. (WARM) ; ; ...and continue with (WARM) (very, very usefull after COLD or RESET !:-)
  429. ; ------------------------------;
  430. CODE STOP ; MUST BE USED before loading another program with new interrupt configuration.
  431. ; ------------------------------;
  432. MOV #0b1010000100,&0x3C0 ; TB0CTL = SMCLK/4, STOP mode, clear timer, no int
  433. BIC.B #0x01,&0x23B ; P4IE.0 disable interrupt for RC5_INT
  434. BIC #1,&0x100 ; disable WDT interval mode interrupt in SFRIE
  435. ASM>FORTH
  436. ['] (WARM) IS WARM \ ; reconnect WARM to (WARM)
  437. -1 ABORT"
  438. ; ; on previous line don't add any char after ABORT", so its message is empty
  439. ; DUP HERE SWAP - DUMP ; general minidump, part 2
  440. FORGET IR_RC5 FORGET WDT_Int ; not FORTH executable
  441. FORGET TOP_LCD FORGET 20_us ; because they are not necessary
  442. FORGET LCD_W FORGET LCD_R ; because they are not necessary
  443. ECHO
  444. ; compiling done
  445. RST_HERE ;
  446. START ; hit key enter :