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

/MSP-EXP430FR5969/MSP-EXP430FR5969_I2C_Slave_to_LCD_2x20.4th

https://gitlab.com/Jean-Michel/FastForthForMSP430fr5xxx
Forth | 548 lines | 496 code | 52 blank | 0 comment | 23 complexity | edfcbd3ac6177a689f515cb4fe09eacb MD5 | raw file
Possible License(s): GPL-3.0
  1. ; -----------------------------------------------
  2. ; MSP-EXP430FR5969_I2C_Slave_to_LCD_2x20.4th
  3. ; -----------------------------------------------
  4. STOP ; to stop any interrupt in progress
  5. WIPE ;
  6. NOECHO ; comment to debug
  7. ; FORTH source file
  8. ; Copyright (C) <2015> <J.M. THOORENS>
  9. ;
  10. ; This program is free software: you can redistribute it and/or modify
  11. ; it under the terms of the GNU General Public License as published by
  12. ; the Free Software Foundation, either version 3 of the License, or
  13. ; (at your option) any later version.
  14. ;
  15. ; This program is distributed in the hope that it will be useful,
  16. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. ; GNU General Public License for more details.
  19. ;
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. ; ========================================
  23. ; DEMO with two MSP-EXP430FR5969 LAUNCHPAD
  24. ; test : I2C_MASTER WRITE & I2C_SLAVE READ
  25. ; ========================================
  26. ; load this MSP-EXP430FR5969_I2C_Slave_to_LCD_2x20.4th file on the first LAUNCHPAD
  27. ; load MSP-EXP430FR5969_RC5_to_I2C_Soft_Master.4th on the other LAUNCHPAD
  28. ; target : MSP-EXP430fr5969 LAUNCHPAD
  29. ; with code : "FORTH_MSP430FR596916MHzTxx.HEX"
  30. ; 1088 bytes
  31. ; ===================================================================================
  32. ; in case of 3.3V powered by UARTtoUSB bridge, open J13 straps {RST,TST,V+,5V} BEFORE
  33. ; ===================================================================================
  34. ; -----------------------------------------------
  35. ; MSP - LAUNCHPAD <--> OUTPUT WORLD
  36. ; -----------------------------------------------
  37. ; P4.6 - J6 - LED1 red
  38. ; P1.0 - LED2 green
  39. ; P4.5 - Switch S1 <--- LCD contrast + (finger :-)
  40. ; P1.1 - Switch S2 <--- LCD contrast - (finger ;-)
  41. ; GND - J1.2 <-------+---0V0----------> 1 LCD_Vss
  42. ; VCC - J1.3 >------ | --3V6-----+----> 2 LCD_Vdd
  43. ; | |
  44. ; |___ 470n ---
  45. ; ^ | ---
  46. ; / \ BAT54 |
  47. ; --- |
  48. ; 100n | 2k2 |
  49. ; P2.2 - J4.7 UCB0 CLK TB0.2 >---||--+--^/\/\/v--+----> 3 LCD_Vo (=0V6 without modulation)
  50. ; P3.4 - J4.8 -------------------------> 4 LCD_RS
  51. ; P3.5 - J4.9 -------------------------> 5 LCD_R/W
  52. ; P3.6 - J4.10 -------------------------> 6 LCD_EN0
  53. ; PJ.0 - J3.1 <------------------------> 11 LCD_DB4
  54. ; PJ.1 - J3.3 <------------------------> 12 LCD_DB5
  55. ; PJ.2 - J3.5 <------------------------> 13 LCD_DB5
  56. ; PJ.3 - J3.7 <------------------------> 14 LCD_DB7
  57. ; P2.0 - J13.8 UCA0 TXD ---> RX UARTtoUSB bridge \
  58. ; P2.1 - J13.10 UCA0 RXD <--- TX UARTtoUSB bridge > <--> COMx <--> TERA TERM
  59. ; P4.1 - J13.14 RTS ---> CTS UARTtoUSB bridge /
  60. ; VCC - J13.16 <--- VCC (optional supply from UARTtoUSB bridge - WARNING ! 3.3V !)
  61. ; GND - J13.20 <--> GND (optional supply from UARTtoUSB bridge)
  62. ; VCC - J11.1 ---> VCC SD_CardAdapter
  63. ; GND - J12.3 <--> GND SD_CardAdapter
  64. ; P2.4 - J4.6 UCA1 CLK ---> CLK SD_CardAdapter (SCK)
  65. ; P4.3 - J4.5 ---> CS SD_CardAdapter (Card Select)
  66. ; P2.5 - J4.4 UCA1 TXD/SIMO ---> SDI SD_CardAdapter (MOSI)
  67. ; P2.6 - J4.3 UCA1 RXD/SOMI <--- SDO SD_CardAdapter (MISO)
  68. ; P4.2 - J4.2 <--- CD SD_CardAdapter (Card Detect)
  69. ; P4.0 - J3.10 \\\ <--- (OUT IR_Receiver (1 TSOP32236))
  70. ; VCC - J3.2 \\\ ---> (VCC IR_Receiver (2 TSOP32236))
  71. ; GND - J3.9 \\\ <--> (GND IR_Receiver (3 TSOP32236))
  72. ; PJ.4 - LFXI 32768Hz quartz
  73. ; PJ.5 - LFXO 32768Hz quartz
  74. ; PJ.6 - HFXI
  75. ; PJ.7 - HFXO
  76. ; P1.2 - J5.19 Soft I2C_Master <--> SDA
  77. ; P1.3 - J5.11 Soft I2C_Master ---> SCL
  78. ; P1.4 - J5.12 TB0.1 <--> free
  79. ; P1.5 - J5.13 UCA0 CLK TB0.2 <--> free
  80. ; P1.6 - J5.15 UCB0 SDA/SIMO <--> SDA <----------------------------------------------------> SDA other LAUNCHPAD
  81. ; P1.7 - J5.14 UCB0 SCL/SOMI <--- SCL <----------------------------------------------------- SCL other LAUNCHPAD
  82. ; P3.0 - J5.7 <--- free
  83. ; P2.3 - NC
  84. ; P2.7 - NC
  85. ; P3.1 - NC
  86. ; P3.2 - NC
  87. ; P3.3 - NC
  88. ; P3.7 - NC
  89. ; P4.4 - NC
  90. ; P4.7 - NC
  91. ; HERE ; general minidump, part 1
  92. ; ******************************;
  93. CODE INT_P1 ; PORT1 interrupt routine, warning : not FORTH executable !
  94. ; ******************************;
  95. BIC #0xF8,0(RSP) ; CPU on, GIE off in retSR
  96. ; ------------------------------;
  97. BIT.B #0x02,&0x200 ; test P1IN.1 = switch S2
  98. BIC.B #0x02,&0x21C ; P1IFG.1 clear
  99. 0= IF ; case of switch S2 pressed
  100. CMP #34,&0x3D6 ; TB0CCR2 ; maxi Ton = 34/40 & VDD=3V6 ==> LCD_Vo = -2V2
  101. U< IF
  102. ADD #1,&0x3D6 ; TB0CCR2 ; action for switch S2 (P1.1) : 78 mV / increment
  103. THEN
  104. THEN
  105. RETI ;
  106. ENDCODE
  107. ; ******************************;
  108. CODE INT_P4 ; PORT4 interrupt routine, warning : not FORTH executable !
  109. ; ******************************;
  110. BIC #0xF8,0(RSP) ; CPU on, GIE off in retSR
  111. ; ------------------------------;
  112. BIT.B #0x20,&0x220 ; test P4IN.5 = switch S1
  113. BIC.B #0x20,&0x23D ; P4IFG.5 clear
  114. 0= IF ; case of Switch S1 pressed
  115. CMP #7,&0x3D6 ; TB0CCR2 ; mini Ton = 6/40 & VDD=3V6 ==> LCD_Vo = 0V
  116. U>= IF ;
  117. SUB #1,&0x3D6 ; TB0CCR2 ; action for switch S1 (P4.5) : -78 mV / decrement
  118. THEN ;
  119. THEN ;
  120. RETI ;
  121. ENDCODE
  122. ; ------------------------------;
  123. CODE 20_us ; n -- n * 20 us
  124. ; ------------------------------;
  125. BEGIN ; 3 cycles loop + 6~
  126. ; MOV #5,W ; 3 MCLK = 1 MHz
  127. ; MOV #23,W ; 3 MCLK = 4 MHz
  128. ; MOV #51,W ; 3 MCLK = 8 MHz
  129. MOV #104,W ; 3 MCLK = 16 MHz
  130. ; MOV #158,W ; 3 MCLK = 24 MHz
  131. BEGIN ; 3 cycles loop ==> 3 * W / F us = 100 us - 1 @ 8 MHz
  132. SUB #1,W ; 1
  133. 0= UNTIL ; 2
  134. SUB #1,TOS ; 1
  135. 0= UNTIL ; 2
  136. MOV @PSP+,TOS ; 2
  137. MOV @IP+,PC ; 4
  138. ENDCODE ; 20 cycles mini with call and return
  139. ; ------------------------------;
  140. CODE TOP_LCD ; LCD Sample
  141. ; ------------------------------; if write : 0bxxxxWWWW --
  142. ; ; if read : -- 0b0000RRRR
  143. BIS.B #0x40,&0x222 ; P3OUT.6 LCD_EN 0-->1
  144. BIT.B #0x20,&0x220 ; P3IN.5 LCD_RW test
  145. 0= IF ; write LCD bits pattern
  146. AND #0x0F,TOS ; keep low nibble
  147. MOV.B TOS, &0x322 ; MOVE LCD_Data bits to PJ(0-3)
  148. BIC.B #0x40,&0x222 ; P3OUT.6 LCD_EN 1-->0 ==> strobe data
  149. MOV @PSP+,TOS ;
  150. MOV @IP+,PC
  151. THEN ; read LCD bits pattern
  152. SUB #2,PSP
  153. MOV TOS,0(PSP)
  154. BIC.B #0x40,&0x222 ; P3OUT.6 LCD_EN 1-->0 ==> strobe data
  155. MOV.B &0x320,TOS ; get LCD_Data from PJ(0-3)
  156. AND.B #0x0F,TOS
  157. MOV @IP+,PC
  158. ENDCODE
  159. ; ------------------------------;
  160. CODE LCD_W ; byte -- write byte
  161. ; ------------------------------;
  162. SUB #2,PSP ;
  163. MOV TOS,0(PSP) ; -- 0bxxxxLLLL 0bHHHHLLLL
  164. RRUM #4,TOS ; -- 0bxxxxLLLL 0bxxxxHHHH
  165. BIC.B #0x20,&0x222 ; P3OUT.5 LCD_RW=0
  166. BIS.B #0x0F,&0x324 ; PJDIR.(0-3) LCD_Data as output
  167. PUSH IP
  168. ASM>FORTH
  169. TOP_LCD 2 20_us \ write high nibble first
  170. TOP_LCD 2 20_us ; ;
  171. ; ------------------------------;
  172. CODE LCD_R ; -- byte read byte
  173. ; ------------------------------;
  174. BIC.B #0x0F,&0x324 ; PJ.(0-3) LCD_Data as intput
  175. BIS.B #0x20,&0x222 ; P3.5 LCD_RW=1
  176. PUSH IP
  177. ASM>FORTH
  178. TOP_LCD 2 20_us \ read high nibble first
  179. TOP_LCD 2 20_us
  180. FORTH>ASM ; -- 0b0000HHHH 0b0000LLLL
  181. MOV @RSP+,IP
  182. MOV @PSP+,W ; W = high nibble
  183. RLAM #4,W ; -- 0b0000LLLL W = 0bHHHH0000
  184. ADD.B W,TOS
  185. MOV @IP+,PC
  186. ENDCODE
  187. ; ------------------------------;
  188. CODE LCD_WrF ; func -- Write Fonction
  189. ; ------------------------------;
  190. BIC.B #0x10,&0x222 ; P3OUT.4 LCD_RS=0
  191. JMP LCD_W
  192. ENDCODE
  193. ; ------------------------------;
  194. CODE LCD_RdS ; -- status Read Status
  195. ; ------------------------------;
  196. BIC.B #0x10,&0x222 ; P3OUT.4 LCD_RS=0
  197. JMP LCD_R
  198. ENDCODE
  199. ; ------------------------------;
  200. CODE LCD_WrC ; char -- Write Char
  201. ; ------------------------------;
  202. BIS.B #0x10,&0x222 ; P3OUT.4 LCD_RS=1
  203. JMP LCD_W
  204. ENDCODE
  205. ; ------------------------------;
  206. CODE LCD_RdC ; -- char Read Char
  207. ; ------------------------------;
  208. BIS.B #0x10,&0x222 ; P3OUT.4 LCD_RS=1
  209. JMP LCD_R
  210. ENDCODE
  211. ; ------------------------------;
  212. ; : LCD_Clear 0x01 LCD_WrF 80 20_us ; ; perhaps bad init
  213. : LCD_Clear 0x01 LCD_WrF 100 20_us ;
  214. ; ------------------------------;
  215. : LCD_Home 0x02 LCD_WrF 80 20_us ;
  216. ; ------------------------------;
  217. ; : LCD_Entry_set 0x04 OR LCD_WrF ;
  218. ; : LCD_Display_Ctrl 0x08 OR LCD_WrF ;
  219. ; : LCD_Display_Shift 0x10 OR LCD_WrF ;
  220. ; : LCD_Fn_Set 0x20 OR LCD_WrF ;
  221. ; : LCD_CGRAM_Set 0x40 OR LCD_WrF ;
  222. ; : LCD_Goto 0x80 OR LCD_WrF ;
  223. VARIABLE MY_I2CADR ; slave I2C address without RW flag (low byte) + DATA0 input (HIGH byte)
  224. 2 ALLOT ; next the low byte of MY_I2CADR word, it is the input buffer
  225. VARIABLE I2CS_OUT ; buffer output, lentgh (low byte),DATA0 output (HIGH byte)
  226. ; 2 ALLOT ; this byte lentgh is shared by input and output buffers
  227. ; **************************************;
  228. CODE I2C_S ; <== eUSCIB0 interrupt vector
  229. ; **************************************;
  230. BIC #0xF8,0(RSP) ; CPU on, GIE off in oldSR
  231. ; --------------------------------------;
  232. MOV #I2CS_OUT,W ; W = buffer output address -1
  233. MOV #MY_I2CADR,X ; X = buffer input address -1
  234. CMP.B @X,&0x65C ; UCBR0ADDRX = own address ?
  235. MOV #0,&0x66C ; write UCB0IFG to clear all int flags
  236. = IF ;
  237. BIS.B #0x20,&0x640 ; UCB0CTLW0(UCTXACK) : software Ack address
  238. BIT.B #0x10,&0X640 ; test UCB0CTLW0(UCTR) R/W bit
  239. 0= IF ; I2C_Master Write ?
  240. ; ------------------------------;
  241. ; slave receive datas ; yes
  242. ; ------------------------------;
  243. MOV X,Y ; Y = input buffer ptr
  244. BEGIN ;
  245. ; --------------------------;
  246. ; slave receive one byte ;
  247. ; --------------------------;
  248. BEGIN ;
  249. BIT.B #0x8C,&0x66C ; UCB0IFG(CLTO,STP,STT,) = 1 ? ( SCL low timeout,STOP, START)
  250. 0<> IF ;
  251. ; ------------------;
  252. ; master stoP/rStart;
  253. ; ------------------;
  254. SUB X,Y ; (ptr-org) = count
  255. MOV.B Y,0(W) ; store length in first byte of buffer output
  256. ; ------------------;
  257. BIS.B #0x40,&0x0223 ; P4.6 OUT high ==> switch ON LED1 to test
  258. ; display IR_RC5 command
  259. SUB #4,PSP ;
  260. MOV &BASE,2(PSP) ; save base
  261. MOV TOS,0(PSP) ;
  262. MOV.B 1(X),TOS ; display RC6 command
  263. ; MOV.B 0(W),TOS ; display count
  264. ASM>FORTH \ ; IP is free
  265. ['] LCD_Clear IS CR
  266. ['] LCD_WrC IS EMIT
  267. CR ." 0x" HEX 2 U.R
  268. SPACE ." LPM = " LPM ? \ display LPM
  269. ['] (CR) IS CR
  270. ['] (EMIT) IS EMIT
  271. FORTH>ASM ; nice code, right ?
  272. MOV @PSP+,&BASE
  273. ; endof display
  274. BIC.B #0x40,&0x0223 ; P4.6 OUT low ==> switch OFF LED1 to test
  275. ; ------------------;
  276. RETI ;
  277. ; ------------------;
  278. THEN ; if not (stop, restart, CLTO)
  279. BIT.B #0x01,&0x66C ; UCB0IFG(RX0) = 1 ?
  280. <> UNTIL ;
  281. ADD #1,Y ; reserve one byte for length first, then preincrement
  282. MOV.B &0x64C,0(Y) ; [UCB0RXBUF] = data --> +[Y]
  283. AGAIN ; loop for new received data if any
  284. THEN ; I2C_Master read
  285. ; ------------------------------;
  286. ; slave transmit datas ; no
  287. ; ------------------------------;
  288. MOV W,Y ; Y = output buffer ptr
  289. ADD #1,Y ; first reserve one byte for length
  290. BEGIN ;
  291. ; --------------------------;
  292. ; slave send byte ;
  293. ; --------------------------;
  294. MOV.B @Y+,&0x64E ; [Y]+ --> UCB0TXBUF
  295. BEGIN ;
  296. BIT.B #0x8C,&0x66C ; UCB0IFG(CLTO,STP,STT,) = 1 ? ( SCL low timeout,STOP, START)
  297. 0<> IF ;
  298. ; ------------------;
  299. ; master stoP/rStart;
  300. ; ------------------;
  301. SUB W,Y ; BUF (ptr-org)= count+1
  302. SUB.B #1,Y ; Y = count
  303. MOV.B Y,0(W) ; store length in buf_out(0)
  304. ; ------------------;
  305. RETI ;
  306. ; ------------------;
  307. THEN ;
  308. BIT.B #0x02,&0x66C ; UCB0IFG(TX0) = 1 ?
  309. <> UNTIL ;
  310. AGAIN ;
  311. THEN ; if bad I2C address
  312. BIC.B #0x20,&0x640 ; UCB0CTLW0(UCTXACK) : send Nack address
  313. RETI ;
  314. ENDCODE
  315. ; PORTA (P2:P1) FastForthForMSP430FR5xxx default I/O state : input with pullup resistors
  316. ; init PORTA (P2:P1) usage
  317. ; P1.0 --> LED2
  318. ; P1.1 <-- Switch S2
  319. ; P1.6 <-> SLAVE SDA
  320. ; P1.7 --> SLAVE SCL
  321. ; P2.0 --> UART0 TX
  322. ; P2.1 <-- UART0 RX
  323. ; P2.2 --> LCD_Vo
  324. ; PORTB (P3:P4) FastForthForMSP430FR5xxx default I/O state : input with pullup resistors
  325. ; P3.4 --> LCD_RS
  326. ; P3.5 --> LCD_RW
  327. ; P3.6 --> LCD_EN
  328. ; P4.5 <-- Switch S1
  329. ; P4.6 --> LED1
  330. ; PORJ FastForthForMSP430FR5xxx default I/O state : input with pullup resistors
  331. ; PJ.0 <-- LCD_DB4
  332. ; PJ.1 <-- LCD_DB5
  333. ; PJ.2 <-- LCD_DB6
  334. ; PJ.3 <-- LCD_DB7
  335. ; --------------------------------------;
  336. CODE START ;
  337. ; --------------------------------------;
  338. ; UCB0CTLW0 = 0b0000 0111 1100 0001 0x640
  339. ; - UCMST = 0 : I2C_Slave
  340. ; -- UCMODE = 0b11 = I2C
  341. ; _ USYNC=1 (always 1)
  342. ; -- UCSSEL=SMCLK (don't care in slave mode)
  343. ; - UCTXACK=0 not auto ACK slave address
  344. ; - UCTR=0 : RX
  345. ; - UCSWRST=1
  346. ; UCB0CTLW1 = 0b0000 0000 1101 0000 0x642
  347. ; - UCETXINT=0 : UCTXIFG0 set address match UCxI2COAx and TX mode
  348. ; -- UCCLTO=0b11 : SCL low time out = 34 ms
  349. ; - UCSWACK=1 : UCTXACK must be written to continue
  350. ; UCB0RXBUF 0x64C
  351. ; UCB0TXBUF 0x64E
  352. ; UCB0I2COA0 0x654 must be written ? enabled ?
  353. ; UCB0ADDRX 0x65C
  354. ; UCB0ADDMSK 0x65E
  355. ; UCB0IE = 0b0000 0000 0000 0100 0x66A
  356. ; - UCSTTIE : StartCond Interrupt only
  357. ; UCB0IFG 0x66C
  358. ; UCB0IV 0x66E : write it to clear all IFG
  359. ; ------------------------------;
  360. ; init I2C_slave ;
  361. ; ------------------------------;
  362. BIS #1,&0x640 ; set eUSCI_B in reset state, clear UCB0IE & UCB0IFG all flags
  363. BIS #0x07A0,&0x640 ;
  364. BIS #0x0010,&0x642 ; UCB0CTLW1 : set software ack address
  365. MOV #0x040A,&0x654 ; UCB0I2COA0 : UCOAEN=1 enable with address slave
  366. MOV #0,&0x65E ; UCB0ADDMSK : enable address mask for all addresses i.e. software address
  367. BIC #1,&0x640 ; activate eUSCI_B
  368. MOV #0x0004,&0x66A ; UCB0IE : enable StartCond interrupt
  369. MOV #0b1010,&MY_I2CADR ; my slave address, without RW flag !
  370. ; MOV #0b1011,&MY_I2CADR ; not my slave address, without RW flag !
  371. ; ------------------------------;
  372. ; init interrupt vectors
  373. ; ------------------------------;
  374. MOV #I2C_S,&0xFFEE ; eUSCIB0 interrupt vector
  375. MOV #INT_P1,&0xFFDE ; init P1 interrupt vector
  376. MOV #INT_P4,&0xFFD0 ; init P4 interrupt vector
  377. ; ----------------------------------;
  378. ; TB0CTL = 0b0000 0010 1001 0100 0x3C0
  379. ; - - CNTL Counter lentgh ; 00 = 16 bits
  380. ; -- TBSSEL TimerB clock select ; 10 = SMCLK
  381. ; -- ID input divider ; 10 = /4
  382. ; -- MC Mode Control ; 01 = up mode
  383. ; - TBCLR TimerB Clear
  384. ; - TBIE
  385. ; - TBIFG
  386. ; ----------------------------------;
  387. ; TB0CCTLx = 0b0000 0000 0110 0000 0x3C{2,4,6,8,A,C,E}
  388. ; -- CM Capture Mode
  389. ; -- CCIS
  390. ; - SCS
  391. ; -- CLLD
  392. ; - CAP
  393. ; --- OUTMOD ; 011 = set/reset
  394. ; - CCIE
  395. ; - CCI
  396. ; - OUT
  397. ; - COV
  398. ; - CCIFG
  399. ; TB0CCRx 0x3D{2,4,6,8,A,C,E}
  400. ; TB0EX0 0x3E0
  401. ; ------------------------------;
  402. ; set TimerB to make 50kHz PWM ;
  403. ; ------------------------------;
  404. ; MOV #0b1000010100,&0x3C0 ; TB0CTL = SMCLK/1, up mode, clear timer, no int
  405. ; MOV #0,&0x03E0 ; predivide by 1 in TB0EX0 register (1 MHZ) (generate 25 kHz)
  406. ; ------------------------------;
  407. ; MOV #0b1000010100,&0x3C0 ; TB0CTL = SMCLK/1, up mode, clear timer, no int
  408. ; MOV #2,&0x03E0 ; predivide by 2 in TB0EX0 register (4 MHZ)
  409. ; ------------------------------;
  410. ; MOV #0b1010010100,&0x3C0 ; TB0CTL = SMCLK/4, up mode, clear timer, no int
  411. ; MOV #0,&0x03E0 ; predivide by 1 in TB0EX0 register (8 MHZ)
  412. ; ------------------------------;
  413. MOV #0b1010010100,&0x3C0 ; TB0CTL = SMCLK/4, up mode, clear timer, no int
  414. MOV #1,&0x03E0 ; predivide by 2 in TB0EX0 register (16 MHZ)
  415. ; ------------------------------;
  416. ; MOV #0b1010010100,&0x3C0 ; TB0CTL = SMCLK/4, up mode, clear timer, no int
  417. ; MOV #3,&0x03E0 ; predivide by 3 in TB0EX0 register (24 MHZ)
  418. ; ------------------------------;
  419. MOV #40,&0x3D2 ; TB0CCR0 = 40*0.5us=20us (40us @ 1MHz)
  420. ; ------------------------------;
  421. ; set TimerB to generate LCD_V0 via TB0.2 and P1.5/P2.2
  422. ; ------------------------------;
  423. MOV #0b1100000,&0x3C6 ; TB0CCTL2 output mode = set/reset ; clear CCIFG
  424. MOV #20,&0x3D6 ; TB0CCR2 ; contrast adjust : 20/40 ==> LCD_Vo = -1V1
  425. ; ------------------------------;
  426. ; set TimerB to generate LCD_V0 via TB0.1 and P1.4/P2.6
  427. ; ------------------------------;
  428. ; MOV #0b1100000,&0x3C4 ; TB0CCTL1 output mode = set/reset
  429. ; MOV #20,&0x3D4 ; TB0CCR1 ; contrast adjust : 20/40 ==> LCD_Vo = -1V1
  430. ; ------------------------------;
  431. ; init PORTA (P2:P1) (complement)
  432. BIC.B #0xC0,&0x206 ; P1REN.76 SDA + SCL pullup/down disable
  433. BIS.B #0xC0,&0x20C ; P1SEL1.76 on : enable I2C I/O
  434. BIS.B #0x02,&0x218 ; P1IES.1 high to low edge select (S2)
  435. BIC.B #0x02,&0x21C ; P1IFG.1 clear (after IES select) (S2)
  436. BIS.B #0x02,&0x21A ; P1IE.1 enable interrupt for S2
  437. BIS.B #0x04,&0x205 ; P2DIR.2 TB0.2 output
  438. BIS.B #0x04,&0x20B ; P2SEL0.2 TB0.2
  439. ; ------------------------------;
  440. ; init PORTB (P4:P3) (complement)
  441. BIS.B #0x70,&0x224 ; P3DIR.456 as outputs, wired to LCD_RS LCD_RW LCD_EN
  442. BIC.B #0x70,&0x226 ; P3REN.456 LCD_RS, LCD_RW, LCD_EN, pullup/down disable
  443. BIC.B #0x30,&0x222 ; P3OUT.45 LCD_RS = LCD_RW = 0
  444. BIS.B #0x20,&0x239 ; P4IES.5 high to low edge select
  445. BIC.B #0x20,&0x23D ; P4IFG.5 clear (after IES select)
  446. BIS.B #0x20,&0x23B ; P4IE.5 enable interrupt for S1
  447. ; ------------------------------;
  448. ; init PORTJ (PJ) (complement)
  449. BIS.B #0x0F,&0x324 ; PJDIR.0123 as output, wired to DB.4567 LCD_Data
  450. BIC.B #0x0F,&0x326 ; PJREN.0123 LCD_Data pullup/down disable
  451. ; ------------------------------;
  452. MOV #0xF8,&LPM ; to enter in LPM4 mode
  453. ; ------------------------------;
  454. ; Init LCD
  455. ; ------------------------------;
  456. ASM>FORTH
  457. 0x03E8 20_us \ ; 1- wait 20 ms
  458. 0x03 TOP_LCD \ ; 2- send DB5=DB4=1
  459. 0xCD 20_us \ ; 3- wait 4,1 ms
  460. 0x03 TOP_LCD \ ; 4- send again DB5=DB4=1
  461. 5 20_us \ ; 5- wait 0,1 ms
  462. 0x03 TOP_LCD \ ; 6- send again again DB5=DB4=1
  463. 2 20_us \ ; wait 40 us = LCD cycle
  464. 0x02 TOP_LCD \ ; 7- send DB5=1 DB4=0
  465. 2 20_us \ ; wait 40 us = LCD cycle
  466. 0x28 LCD_WrF \ ; 8- 0b001DNFxx "FonctionSet" D=8/4 DataBus width, Number of lines=2/1, Font bold/normal
  467. 0x08 LCD_WrF \ ; 9- 0b1DCB "DisplayControl" : Display off, Cursor off, Blink off.
  468. LCD_Clear \ ; 10- "LCD_Clear"
  469. 0x06 LCD_WrF \ ; 11- 0b01xx "LCD_EntrySet" : address and cursor shift after writing in RAM
  470. 0x0C LCD_WrF \ ; 12- 0b1DCB "DisplayControl" : Display on, Cursor off, Blink off.
  471. ['] LCD_WrC IS EMIT \ EMIT is redirected to LCD_WrC
  472. CR ." SYSRSTIV = "
  473. HEX 0x1800 @ 2 U.R \ print SAVE_SYSRSTIV
  474. ['] (EMIT) IS EMIT \ restore EMIT
  475. ." Type STOP to quit I2C_Slave_to_LCD"
  476. LIT RECURSE IS WARM \ ; redirect WARM to START...
  477. (WARM) ; ; ...and finish START with (WARM)
  478. CODE STOP
  479. MOV #0b1010000100,&0x3C0 ; TB0CTL = SMCLK/4, STOP mode, clear timer, no int
  480. MOV #1,&0x640 ; set eUSCI_B in reset state, clear UCB0IE & UCB0IFG flags
  481. BIC.B #0x02,&0x21A ; P1IE.1 disable interrupt for S2
  482. BIC.B #0x20,&0x23B ; P4IE.5 disable interrupt for S1
  483. ASM>FORTH
  484. ['] (WARM) IS WARM \ ; reconnect WARM to (WARM)
  485. -1 ABORT"
  486. ;
  487. ; DUP HERE SWAP - DUMP ; general minidump, part 2
  488. ; words
  489. FORGET I2C_S ; not FORTH executable
  490. FORGET INT_P1 FORGET INT_P4 ; not FORTH executable
  491. FORGET 20_us FORGET LCD_W ; because they are not necessary
  492. FORGET LCD_R FORGET TOP_LCD ; because they are not necessary
  493. ECHO
  494. ; compiling done
  495. RST_HERE ;
  496. START ; hit key enter :