University projects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1154 lines
41 KiB

  1. CCS PCM C Compiler, Version 3.239, 31482 05-Feb-07 19:32
  2. Filename: Y:\Year 2\EE2A\PIC-LCD\4bit\lcd_display.lst
  3. ROM used: 441 words (11%)
  4. Largest free fragment is 2048
  5. RAM used: 71 (41%) at main() level
  6. 80 (46%) worst case
  7. Stack: 5 locations
  8. *
  9. 0000: MOVLW 00
  10. 0001: MOVWF 0A
  11. 0002: GOTO 10A
  12. 0003: NOP
  13. .................... /* LCD string program
  14. .................... * This program sends strings to an LCD via the 8 or 4 bit driver
  15. .................... * included in the header.
  16. .................... */
  17. ....................
  18. .................... #include <16F648A.h>
  19. .................... //////// Standard Header file for the PIC16F648A device ////////////////
  20. .................... #device PIC16F648A
  21. .................... #list
  22. ....................
  23. .................... #include <string.h>
  24. .................... ////////////////////////////////////////////////////////////////////////////
  25. .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
  26. .................... //// This source code may only be used by licensed users of the CCS C ////
  27. .................... //// compiler. This source code may only be distributed to other ////
  28. .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
  29. .................... //// or distribution is permitted without written permission. ////
  30. .................... //// Derivative programs created using this software in object code ////
  31. .................... //// form are not restricted in any way. ////
  32. .................... ////////////////////////////////////////////////////////////////////////////
  33. ....................
  34. .................... #ifndef _STRING
  35. .................... #define _STRING
  36. .................... #include <stddef.h>
  37. .................... ///////////////////////////////////////////////////////////////////////////
  38. .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
  39. .................... //// This source code may only be used by licensed users of the CCS C ////
  40. .................... //// compiler. This source code may only be distributed to other ////
  41. .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
  42. .................... //// or distribution is permitted without written permission. ////
  43. .................... //// Derivative programs created using this software in object code ////
  44. .................... //// form are not restricted in any way. ////
  45. .................... ///////////////////////////////////////////////////////////////////////////
  46. ....................
  47. .................... #ifndef _STDDEF
  48. ....................
  49. .................... #define _STDDEF
  50. ....................
  51. .................... #if sizeof(int *)==1
  52. .................... #define ptrdiff_t int
  53. .................... #else
  54. .................... #define ptrdiff_t long
  55. .................... #endif
  56. ....................
  57. .................... #define size_t int
  58. .................... #define wchar_t char
  59. .................... #define NULL 0
  60. ....................
  61. .................... #define offsetof(s,f) (offsetofbit(s,f)/8)
  62. ....................
  63. .................... #endif
  64. ....................
  65. .................... #include <ctype.h>
  66. .................... ////////////////////////////////////////////////////////////////////////////
  67. .................... //// (C) Copyright 1996,2003 Custom Computer Services ////
  68. .................... //// This source code may only be used by licensed users of the CCS C ////
  69. .................... //// compiler. This source code may only be distributed to other ////
  70. .................... //// licensed users of the CCS C compiler. No other use, reproduction ////
  71. .................... //// or distribution is permitted without written permission. ////
  72. .................... //// Derivative programs created using this software in object code ////
  73. .................... //// form are not restricted in any way. ////
  74. .................... ////////////////////////////////////////////////////////////////////////////
  75. ....................
  76. .................... #ifndef _CTYPE
  77. .................... #define _CTYPE
  78. ....................
  79. .................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz")
  80. .................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ")
  81. .................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
  82. .................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
  83. .................... #define isdigit(x) isamong(x,"0123456789")
  84. .................... #define isspace(x) (x==' ')
  85. .................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef")
  86. .................... #define iscntrl(x) (x<' ')
  87. .................... #define isprint(x) (x>=' ')
  88. .................... #define isgraph(x) (x>' ')
  89. .................... #define ispunct(x) ((x>' ')&&!isalnum(x))
  90. ....................
  91. .................... #endif
  92. ....................
  93. ....................
  94. ....................
  95. ....................
  96. ....................
  97. .................... //////////////////////////////////////////////
  98. .................... //// Uncomment the following define to ////
  99. .................... //// allow some functions to use a ////
  100. .................... //// quicker algorithm, but use more ROM ////
  101. .................... //// ////
  102. .................... //// #define FASTER_BUT_MORE_ROM ////
  103. .................... //////////////////////////////////////////////
  104. ....................
  105. ....................
  106. ....................
  107. .................... /*Copying functions*/
  108. .................... /* standard template:
  109. .................... void *memmove(void *s1, void *s2, size_t n).
  110. .................... Copies max of n characters safely (not following ending '\0')
  111. .................... from s2 in s1; if s2 has less than n characters, appends 0 */
  112. ....................
  113. .................... char *memmove(void *s1,char *s2,size_t n)
  114. .................... {
  115. .................... char *sc1;
  116. .................... char *sc2;
  117. .................... sc1=s1;
  118. .................... sc2=s2;
  119. .................... if(sc2<sc1 && sc1 <sc2 +n)
  120. .................... for(sc1+=n,sc2+=n;0<n;--n)
  121. .................... *--sc1=*--sc2;
  122. .................... else
  123. .................... for(;0<n;--n)
  124. .................... *sc1++=*sc2++;
  125. .................... return s1;
  126. .................... }
  127. ....................
  128. .................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved?
  129. .................... Standard template: char *strcpy(char *s1, const char *s2)
  130. .................... copies the string s2 including the null character to s1*/
  131. ....................
  132. .................... char *strcopy(char *s1, char *s2)
  133. .................... {
  134. .................... char *s;
  135. ....................
  136. .................... for (s = s1; *s2 != 0; s++, s2++) {
  137. .................... *s = *s2;
  138. .................... }
  139. .................... *s = *s2;
  140. .................... return(s1);
  141. .................... }
  142. ....................
  143. .................... /* standard template:
  144. .................... char *strncpy(char *s1, const char *s2, size_t n).
  145. .................... Copies max of n characters (not following ending '\0')
  146. .................... from s2 in s1; if s2 has less than n characters, appends 0 */
  147. ....................
  148. .................... char *strncpy(char *s1, char *s2, size_t n)
  149. .................... {
  150. .................... char *s;
  151. ....................
  152. .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
  153. .................... *s++ = *s2++;
  154. .................... for (; n > 0; n--)
  155. .................... *s++ = '\0';
  156. ....................
  157. .................... return(s1);
  158. .................... }
  159. .................... /***********************************************************/
  160. ....................
  161. .................... /*concatenation functions*/
  162. .................... /* standard template: char *strcat(char *s1, const char *s2)
  163. .................... appends s2 to s1*/
  164. ....................
  165. .................... char *strcat(char *s1, char *s2)
  166. .................... {
  167. .................... char *s;
  168. ....................
  169. .................... for (s = s1; *s != '\0'; ++s);
  170. .................... while(*s2 != '\0')
  171. .................... {
  172. .................... *s = *s2;
  173. .................... ++s;
  174. .................... ++s2;
  175. .................... }
  176. ....................
  177. .................... *s = '\0';
  178. .................... return(s1);
  179. .................... }
  180. .................... /* standard template: char *strncat(char *s1, char *s2,size_t n)
  181. .................... appends not more than n characters from s2 to s1*/
  182. ....................
  183. .................... char *strncat(char *s1, char *s2, size_t n)
  184. .................... {
  185. .................... char *s;
  186. ....................
  187. .................... for (s = s1; *s != '\0'; ++s);
  188. .................... while(*s2 != '\0' && 0<n)
  189. .................... {
  190. .................... *s = *s2;
  191. .................... ++s;
  192. .................... ++s2;
  193. .................... --n;
  194. .................... }
  195. ....................
  196. .................... *s = '\0';
  197. .................... return(s1);
  198. .................... }
  199. ....................
  200. .................... /***********************************************************/
  201. ....................
  202. ....................
  203. .................... /*comparison functions*/
  204. .................... /* standard template: signed int memcmp(void *s1, void *s2).
  205. .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
  206. ....................
  207. .................... signed int memcmp(void * s1,char *s2,size_t n)
  208. .................... {
  209. .................... char *su1, *su2;
  210. .................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n)
  211. .................... {
  212. .................... if(*su1!=*su2)
  213. .................... return ((*su1<*su2)?-1:+1);
  214. .................... }
  215. .................... return 0;
  216. .................... }
  217. ....................
  218. .................... /* standard template: int strcmp(const char *s1, const char *s2).
  219. .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
  220. ....................
  221. .................... signed int strcmp(char *s1, char *s2)
  222. .................... {
  223. .................... for (; *s1 == *s2; s1++, s2++)
  224. .................... if (*s1 == '\0')
  225. .................... return(0);
  226. .................... return((*s1 < *s2) ? -1: 1);
  227. .................... }
  228. .................... /* standard template: int strcoll(const char *s1, const char *s2).
  229. .................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */
  230. ....................
  231. .................... signed int strcoll(char *s1, char *s2)
  232. .................... {
  233. .................... for (; *s1 == *s2; s1++, s2++)
  234. .................... if (*s1 == '\0')
  235. .................... return(0);
  236. .................... return((*s1 < *s2) ? -1: 1);
  237. .................... }
  238. ....................
  239. .................... /* standard template:
  240. .................... int strncmp(const char *s1, const char *s2, size_t n).
  241. .................... Compares max of n characters (not following 0) from s1 to s2;
  242. .................... returns same as strcmp */
  243. ....................
  244. .................... signed int strncmp(char *s1, char *s2, size_t n)
  245. .................... {
  246. .................... for (; n > 0; s1++, s2++, n--)
  247. .................... if (*s1 != *s2)
  248. .................... return((*s1 <*s2) ? -1: 1);
  249. .................... else if (*s1 == '\0')
  250. .................... return(0);
  251. .................... return(0);
  252. .................... }
  253. .................... /* standard template:
  254. .................... int strxfrm(const char *s1, const char *s2, size_t n).
  255. .................... transforms maximum of n characters from s2 and places them into s1*/
  256. .................... size_t strxfrm(char *s1, char *s2, size_t n)
  257. .................... {
  258. .................... char *s;
  259. .................... int n1;
  260. .................... n1=n;
  261. .................... for (s = s1; n > 0 && *s2 != '\0'; n--)
  262. .................... *s++ = *s2++;
  263. .................... for (; n > 0; n--)
  264. .................... *s++ = '\0';
  265. ....................
  266. .................... return(n1);
  267. .................... }
  268. ....................
  269. ....................
  270. ....................
  271. ....................
  272. ....................
  273. .................... /***********************************************************/
  274. .................... /*Search functions*/
  275. .................... /* standard template: void *memchr(const char *s, int c).
  276. .................... Finds first occurrence of c in n characters of s */
  277. ....................
  278. .................... char *memchr(void *s,int c,size_t n)
  279. .................... {
  280. .................... char uc;
  281. .................... char *su;
  282. .................... uc=c;
  283. .................... for(su=s;0<n;++su,--n)
  284. .................... if(*su==uc)
  285. .................... return su;
  286. .................... return NULL;
  287. .................... }
  288. ....................
  289. .................... /* standard template: char *strchr(const char *s, int c).
  290. .................... Finds first occurrence of c in s */
  291. ....................
  292. .................... char *strchr(char *s, int c)
  293. .................... {
  294. .................... for (; *s != c; s++)
  295. .................... if (*s == '\0')
  296. .................... return(0);
  297. .................... return(s);
  298. .................... }
  299. .................... /* standard template:
  300. .................... size_t strcspn(const char *s1, const char *s2).
  301. .................... Computes length of max initial segment of s1 that
  302. .................... consists entirely of characters NOT from s2*/
  303. ....................
  304. .................... int *strcspn(char *s1, char *s2)
  305. .................... {
  306. .................... char *sc1, *sc2;
  307. ....................
  308. .................... for (sc1 = s1; *sc1 != 0; sc1++)
  309. .................... for (sc2 = s2; *sc2 != 0; sc2++)
  310. .................... if (*sc1 == *sc2)
  311. .................... return(sc1 - s1);
  312. .................... return(sc1 - s1);
  313. .................... }
  314. .................... /* standard template:
  315. .................... char *strpbrk(const char *s1, const char *s2).
  316. .................... Locates first occurence of any character from s2 in s1;
  317. .................... returns s1 if s2 is empty string */
  318. ....................
  319. .................... char *strpbrk(char *s1, char *s2)
  320. .................... {
  321. .................... char *sc1, *sc2;
  322. ....................
  323. .................... for (sc1 = s1; *sc1 != 0; sc1++)
  324. .................... for (sc2 = s2; *sc2 != 0; sc2++)
  325. .................... if (*sc1 == *sc2)
  326. .................... return(sc1);
  327. .................... return(0);
  328. .................... }
  329. ....................
  330. ....................
  331. .................... /* standard template: char *strrchr(const char *s, int c).
  332. .................... Finds last occurrence of c in s */
  333. ....................
  334. .................... char *strrchr(char *s, int c)
  335. .................... {
  336. .................... char *p;
  337. ....................
  338. .................... for (p = 0; ; s++)
  339. .................... {
  340. .................... if (*s == c)
  341. .................... p = s;
  342. .................... if (*s == '\0')
  343. .................... return(p);
  344. .................... }
  345. .................... }
  346. .................... /* computes length of max initial segment of s1 consisting
  347. .................... entirely of characters from s2 */
  348. ....................
  349. .................... int *strspn(char *s1, char *s2)
  350. .................... {
  351. .................... char *sc1, *sc2;
  352. ....................
  353. .................... for (sc1 = s1; *sc1 != 0; sc1++)
  354. .................... for (sc2 = s2; ; sc2++)
  355. .................... if (*sc2 == '\0')
  356. .................... return(sc1 - s1);
  357. .................... else if (*sc1 == *sc2)
  358. .................... break;
  359. .................... return(sc1 - s1);
  360. .................... }
  361. .................... /* standard template:
  362. .................... char *strstr(const char *s1, const char *s2);
  363. .................... Locates first occurence of character sequence s2 in s1;
  364. .................... returns 0 if s2 is empty string
  365. ....................
  366. .................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the
  367. .................... file to use the faster algorithm */
  368. .................... char *strstr(char *s1, char *s2)
  369. .................... {
  370. .................... char *s, *t;
  371. ....................
  372. .................... #ifdef FASTER_BUT_MORE_ROM
  373. .................... if (*s2 == '\0')
  374. .................... return(s1);
  375. .................... #endif
  376. ....................
  377. .................... while (*s1)
  378. .................... {
  379. .................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t);
  380. ....................
  381. .................... if (*t == '\0')
  382. .................... return s1;
  383. .................... ++s1;
  384. .................... #ifdef FASTER_BUT_MORE_ROM
  385. .................... while(*s1 != '\0' && *s1 != *s2)
  386. .................... ++s1;
  387. .................... #endif
  388. .................... }
  389. .................... return 0;
  390. .................... }
  391. ....................
  392. .................... /* standard template: char *strtok(char *s1, const char *s2).
  393. ....................
  394. .................... Finds next token in s1 delimited by a character from separator
  395. .................... string s2 (which can be different from call to call). First call
  396. .................... starts at beginning of s1 searching for first character NOT
  397. .................... contained in s2; returns 0 if none is found.
  398. .................... If one is found, it is the start of first token (return value).
  399. .................... Function then searches from there for a character contained in s2.
  400. .................... If none is found, current token extends to end of s1, and subsequent
  401. .................... searches for a token will return 0. If one is found, it is
  402. .................... overwritten by '\0', which terminates current token. Function saves
  403. .................... pointer to following character from which next search will start.
  404. .................... Each subsequent call, with 0 as first argument, starts searching
  405. .................... from saved pointer */
  406. ....................
  407. .................... char *strtok(char *s1, char *s2)
  408. .................... {
  409. .................... char *beg, *end;
  410. .................... static char *save;
  411. *
  412. 010F: CLRF 20
  413. ....................
  414. .................... beg = (s1)? s1: save;
  415. .................... beg += strspn(beg, s2);
  416. .................... if (*beg == '\0')
  417. .................... {
  418. .................... *save = ' ';
  419. .................... return(0);
  420. .................... }
  421. .................... end = strpbrk(beg, s2);
  422. .................... if (*end != '\0')
  423. .................... {
  424. .................... *end = '\0';
  425. .................... end++;
  426. .................... }
  427. .................... save = end;
  428. .................... return(beg);
  429. .................... }
  430. ....................
  431. .................... /*****************************************************************/
  432. .................... /*Miscellaneous functions*/
  433. .................... /* standard template
  434. .................... maps error number in errnum to an error message string
  435. .................... Returns: Pointer to string
  436. .................... */
  437. .................... #ifdef _ERRNO
  438. .................... char * strerror(int errnum)
  439. .................... {
  440. .................... char s[15];
  441. .................... switch( errnum)
  442. .................... {
  443. .................... case 0:
  444. .................... strcpy(s,"no errors");
  445. .................... return s;
  446. .................... case EDOM :
  447. .................... strcpy(s,"domain error");
  448. .................... return s;
  449. .................... case ERANGE:
  450. .................... strcpy(s,"range error");
  451. .................... return s;
  452. .................... }
  453. .................... }
  454. .................... #ENDIF
  455. .................... /* standard template: size_t strlen(const char *s).
  456. .................... Computes length of s1 (preceding terminating 0) */
  457. ....................
  458. .................... int *strlen(char *s)
  459. .................... {
  460. .................... char *sc;
  461. ....................
  462. .................... for (sc = s; *sc != 0; sc++);
  463. .................... return(sc - s);
  464. .................... }
  465. ....................
  466. .................... /* standard template: size_t stricmp(const char *s1, const char *s2).
  467. .................... Compares s1 to s2 ignoring case (upper vs. lower) */
  468. ....................
  469. .................... signed int stricmp(char *s1, char *s2)
  470. .................... {
  471. .................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32));
  472. .................... s1++, s2++)
  473. .................... if (*s1 == '\0')
  474. .................... return(0);
  475. .................... return((*s1 < *s2) ? -1: 1);
  476. .................... }
  477. ....................
  478. ....................
  479. .................... /* standard template: char *strlwr(char *s).
  480. .................... Replaces uppercase letters by lowercase;
  481. .................... returns pointer to new string s */
  482. ....................
  483. .................... char *strlwr(char *s)
  484. .................... {
  485. .................... char *p;
  486. ....................
  487. .................... for (p = s; *p != '\0'; p++)
  488. .................... if (*p >= 'A' && *p <='Z')
  489. .................... *p += 'a' - 'A';
  490. .................... return(s);
  491. .................... }
  492. ....................
  493. ....................
  494. .................... /************************************************************/
  495. ....................
  496. ....................
  497. .................... #endif
  498. ....................
  499. .................... #use delay(clock=4000000)
  500. *
  501. 001C: MOVLW 6A
  502. 001D: MOVWF 04
  503. 001E: MOVF 00,W
  504. 001F: BTFSC 03.2
  505. 0020: GOTO 030
  506. 0021: MOVLW 01
  507. 0022: MOVWF 78
  508. 0023: CLRF 77
  509. 0024: DECFSZ 77,F
  510. 0025: GOTO 024
  511. 0026: DECFSZ 78,F
  512. 0027: GOTO 023
  513. 0028: MOVLW 4A
  514. 0029: MOVWF 77
  515. 002A: DECFSZ 77,F
  516. 002B: GOTO 02A
  517. 002C: NOP
  518. 002D: NOP
  519. 002E: DECFSZ 00,F
  520. 002F: GOTO 021
  521. 0030: RETLW 00
  522. .................... #fuses NOWDT, INTRC_IO, NOPUT, NOPROTECT, NOLVP, NOMCLR
  523. .................... #include "LCD_4BIT.H"
  524. .................... /* LCD 4-bit driver */
  525. ....................
  526. .................... struct lcd_pin_map {
  527. .................... boolean rs;
  528. .................... boolean rw;
  529. .................... boolean enable;
  530. .................... boolean button;
  531. .................... int data : 4;
  532. .................... };
  533. ....................
  534. .................... /* Create stucts to map I/O */
  535. .................... struct lcd_pin_map lcd;
  536. .................... struct lcd_pin_map lcd_dir;
  537. ....................
  538. .................... /* Set ports up correctly */
  539. .................... #byte lcd=0x06
  540. .................... #byte lcd_dir=0x86
  541. ....................
  542. .................... /* Send initialization sequence */
  543. .................... /* No cursor */
  544. .................... byte CONST lcd_init_nocursor[4] = {0x28, 0x0C, 0x01, 0x06};
  545. .................... /* Cursor */
  546. .................... byte CONST lcd_init_cursor[4] = {0x28, 0x0E, 0x01, 0x06};
  547. .................... /* Scrolling */
  548. .................... byte CONST lcd_init_scrolling[4] = {0x20, 0x0C, 0x01, 0x05};
  549. ....................
  550. .................... /* Set direction of pins to send chars to LCD */
  551. .................... /* RS, RW, ENABLE, BUTTON, DATA */
  552. .................... struct lcd_pin_map CONST lcd_write = {0, 0, 0, 1, 0};
  553. ....................
  554. .................... /* Set direction of pins to read status from LCD */
  555. .................... struct lcd_pin_map CONST lcd_read = {1, 0, 0, 1, 1};
  556. ....................
  557. .................... /* Based on lcd.c */
  558. .................... void lcd_send_nibble( byte n ) {
  559. ....................
  560. .................... lcd.enable = 1;
  561. 0031: BSF 06.2
  562. .................... delay_us(50);
  563. 0032: MOVLW 10
  564. 0033: MOVWF 77
  565. 0034: DECFSZ 77,F
  566. 0035: GOTO 034
  567. 0036: NOP
  568. .................... lcd.data = n;
  569. 0037: SWAPF 69,W
  570. 0038: ANDLW F0
  571. 0039: MOVWF 77
  572. 003A: MOVLW 0F
  573. 003B: ANDWF 06,W
  574. 003C: IORWF 77,W
  575. 003D: MOVWF 06
  576. .................... delay_ms(1);
  577. 003E: MOVLW 01
  578. 003F: MOVWF 6A
  579. 0040: CALL 01C
  580. .................... lcd.enable = 0;
  581. 0041: BCF 06.2
  582. .................... delay_us(50);
  583. 0042: MOVLW 10
  584. 0043: MOVWF 77
  585. 0044: DECFSZ 77,F
  586. 0045: GOTO 044
  587. 0046: NOP
  588. .................... }
  589. 0047: RETLW 00
  590. ....................
  591. .................... /* Based on lcd.C */
  592. .................... void lcd_send_byte( byte address, byte n ) {
  593. ....................
  594. .................... /* Set port direction */
  595. .................... lcd_dir = lcd_write;
  596. 0048: MOVLW 08
  597. 0049: BSF 03.5
  598. 004A: MOVWF 06
  599. .................... /* Set what we are writing to */
  600. .................... /* 0 is Instruction */
  601. .................... /* 1 is Data */
  602. .................... lcd.rs = address;
  603. 004B: BCF 03.5
  604. 004C: BTFSS 66.0
  605. 004D: BCF 06.0
  606. 004E: BTFSC 66.0
  607. 004F: BSF 06.0
  608. .................... /* Write to LCD */
  609. .................... lcd.rw = 0;
  610. 0050: BCF 06.1
  611. .................... delay_us(500);
  612. 0051: MOVLW A6
  613. 0052: MOVWF 77
  614. 0053: DECFSZ 77,F
  615. 0054: GOTO 053
  616. 0055: NOP
  617. .................... lcd_send_nibble(n>>4);
  618. 0056: SWAPF 67,W
  619. 0057: MOVWF 68
  620. 0058: MOVLW 0F
  621. 0059: ANDWF 68,F
  622. 005A: MOVF 68,W
  623. 005B: MOVWF 69
  624. 005C: CALL 031
  625. .................... delay_ms(1);
  626. 005D: MOVLW 01
  627. 005E: MOVWF 6A
  628. 005F: CALL 01C
  629. .................... lcd_send_nibble(n & 0xf);
  630. 0060: MOVF 67,W
  631. 0061: ANDLW 0F
  632. 0062: MOVWF 68
  633. 0063: MOVWF 69
  634. 0064: CALL 031
  635. .................... /* Reset RW/RS */
  636. .................... lcd.rw = 1;
  637. 0065: BSF 06.1
  638. .................... lcd.rs = 0;
  639. 0066: BCF 06.0
  640. .................... delay_us(500);
  641. 0067: MOVLW A6
  642. 0068: MOVWF 77
  643. 0069: DECFSZ 77,F
  644. 006A: GOTO 069
  645. 006B: NOP
  646. ....................
  647. .................... }
  648. 006C: RETLW 00
  649. ....................
  650. .................... /* Based on LCD.C */
  651. .................... boolean lcd_read_status() {
  652. ....................
  653. .................... boolean status;
  654. .................... /* Set port direction */
  655. .................... lcd_dir = lcd_read;
  656. .................... /* Read from the LCD */
  657. .................... lcd.rw = 1;
  658. .................... delay_us(1);
  659. .................... lcd.enable = 1;
  660. .................... delay_us(1);
  661. .................... status = lcd.rs;
  662. .................... lcd.enable = 0;
  663. .................... delay_us(2);
  664. .................... /* Return the status */
  665. .................... return(status);
  666. .................... }
  667. ....................
  668. .................... /* Based on LCD.C */
  669. .................... void lcd_init(int init) {
  670. ....................
  671. .................... int i;
  672. ....................
  673. .................... lcd_dir = lcd_write;
  674. 006D: MOVLW 08
  675. 006E: BSF 03.5
  676. 006F: MOVWF 06
  677. .................... lcd.rs = 0;
  678. 0070: BCF 03.5
  679. 0071: BCF 06.0
  680. .................... lcd.rw = 0;
  681. 0072: BCF 06.1
  682. .................... lcd.enable = 0;
  683. 0073: BCF 06.2
  684. .................... delay_ms(15);
  685. 0074: MOVLW 0F
  686. 0075: MOVWF 6A
  687. 0076: CALL 01C
  688. ....................
  689. .................... for(i=0; i<=3; i++) {
  690. 0077: CLRF 62
  691. 0078: MOVF 62,W
  692. 0079: SUBLW 03
  693. 007A: BTFSS 03.0
  694. 007B: GOTO 084
  695. .................... lcd_send_nibble(0x03);
  696. 007C: MOVLW 03
  697. 007D: MOVWF 69
  698. 007E: CALL 031
  699. .................... delay_ms(5);
  700. 007F: MOVLW 05
  701. 0080: MOVWF 6A
  702. 0081: CALL 01C
  703. .................... }
  704. 0082: INCF 62,F
  705. 0083: GOTO 078
  706. ....................
  707. .................... /* Semd extra init nibble */
  708. .................... lcd_send_nibble(0x02);
  709. 0084: MOVLW 02
  710. 0085: MOVWF 69
  711. 0086: CALL 031
  712. .................... delay_ms(5);
  713. 0087: MOVLW 05
  714. 0088: MOVWF 6A
  715. 0089: CALL 01C
  716. ....................
  717. .................... switch (init) {
  718. 008A: MOVF 61,W
  719. 008B: XORLW 01
  720. 008C: BTFSC 03.2
  721. 008D: GOTO 095
  722. 008E: XORLW 03
  723. 008F: BTFSC 03.2
  724. 0090: GOTO 0A4
  725. 0091: XORLW 01
  726. 0092: BTFSC 03.2
  727. 0093: GOTO 0B3
  728. 0094: GOTO 0C2
  729. .................... case 1 : for(i=0; i<=3; i++)
  730. 0095: CLRF 62
  731. 0096: MOVF 62,W
  732. 0097: SUBLW 03
  733. 0098: BTFSS 03.0
  734. 0099: GOTO 0A3
  735. .................... lcd_send_byte(0, lcd_init_nocursor[i]); break;
  736. 009A: MOVF 62,W
  737. 009B: CALL 004
  738. 009C: MOVWF 63
  739. 009D: CLRF 66
  740. 009E: MOVF 63,W
  741. 009F: MOVWF 67
  742. 00A0: CALL 048
  743. 00A1: INCF 62,F
  744. 00A2: GOTO 096
  745. 00A3: GOTO 0D1
  746. .................... case 2 : for(i=0; i<=3; i++)
  747. 00A4: CLRF 62
  748. 00A5: MOVF 62,W
  749. 00A6: SUBLW 03
  750. 00A7: BTFSS 03.0
  751. 00A8: GOTO 0B2
  752. .................... lcd_send_byte(0, lcd_init_cursor[i]); break;
  753. 00A9: MOVF 62,W
  754. 00AA: CALL 00C
  755. 00AB: MOVWF 63
  756. 00AC: CLRF 66
  757. 00AD: MOVF 63,W
  758. 00AE: MOVWF 67
  759. 00AF: CALL 048
  760. 00B0: INCF 62,F
  761. 00B1: GOTO 0A5
  762. 00B2: GOTO 0D1
  763. .................... case 3 : for(i=0; i<=3; i++)
  764. 00B3: CLRF 62
  765. 00B4: MOVF 62,W
  766. 00B5: SUBLW 03
  767. 00B6: BTFSS 03.0
  768. 00B7: GOTO 0C1
  769. .................... lcd_send_byte(0, lcd_init_scrolling[i]); break;
  770. 00B8: MOVF 62,W
  771. 00B9: CALL 014
  772. 00BA: MOVWF 63
  773. 00BB: CLRF 66
  774. 00BC: MOVF 63,W
  775. 00BD: MOVWF 67
  776. 00BE: CALL 048
  777. 00BF: INCF 62,F
  778. 00C0: GOTO 0B4
  779. 00C1: GOTO 0D1
  780. .................... default : for(i=0; i<=3; i++)
  781. 00C2: CLRF 62
  782. 00C3: MOVF 62,W
  783. 00C4: SUBLW 03
  784. 00C5: BTFSS 03.0
  785. 00C6: GOTO 0D0
  786. .................... lcd_send_byte(0, lcd_init_nocursor[i]); break;
  787. 00C7: MOVF 62,W
  788. 00C8: CALL 004
  789. 00C9: MOVWF 63
  790. 00CA: CLRF 66
  791. 00CB: MOVF 63,W
  792. 00CC: MOVWF 67
  793. 00CD: CALL 048
  794. 00CE: INCF 62,F
  795. 00CF: GOTO 0C3
  796. 00D0: GOTO 0D1
  797. .................... }
  798. .................... }
  799. 00D1: RETLW 00
  800. ....................
  801. .................... /* Based on lcd.C */
  802. .................... void lcd_putc( char c ) {
  803. .................... switch (c) {
  804. 00D2: MOVF 65,W
  805. 00D3: XORLW 0C
  806. 00D4: BTFSC 03.2
  807. 00D5: GOTO 0DD
  808. 00D6: XORLW 04
  809. 00D7: BTFSC 03.2
  810. 00D8: GOTO 0E5
  811. 00D9: XORLW 02
  812. 00DA: BTFSC 03.2
  813. 00DB: GOTO 0EA
  814. 00DC: GOTO 0EF
  815. .................... /* clear the screen */
  816. .................... case '\f' : lcd_send_byte(0, 0x01);
  817. 00DD: CLRF 66
  818. 00DE: MOVLW 01
  819. 00DF: MOVWF 67
  820. 00E0: CALL 048
  821. .................... delay_ms(2); break;
  822. 00E1: MOVLW 02
  823. 00E2: MOVWF 6A
  824. 00E3: CALL 01C
  825. 00E4: GOTO 0F5
  826. .................... /* back space */
  827. .................... case '\b' : lcd_send_byte(0, 0x08); break;
  828. 00E5: CLRF 66
  829. 00E6: MOVLW 08
  830. 00E7: MOVWF 67
  831. 00E8: CALL 048
  832. 00E9: GOTO 0F5
  833. .................... /* new line */
  834. .................... case '\n' : lcd_send_byte(0, 0xC0); break;
  835. 00EA: CLRF 66
  836. 00EB: MOVLW C0
  837. 00EC: MOVWF 67
  838. 00ED: CALL 048
  839. 00EE: GOTO 0F5
  840. ....................
  841. .................... default : lcd_send_byte(1, c); break;
  842. 00EF: MOVLW 01
  843. 00F0: MOVWF 66
  844. 00F1: MOVF 65,W
  845. 00F2: MOVWF 67
  846. 00F3: CALL 048
  847. 00F4: GOTO 0F5
  848. .................... }
  849. .................... }
  850. 00F5: RETLW 00
  851. ....................
  852. ....................
  853. ....................
  854. ....................
  855. .................... char INITMESSAGE[16] = "How can I help?";
  856. *
  857. 0110: MOVLW 48
  858. 0111: MOVWF 21
  859. 0112: MOVLW 6F
  860. 0113: MOVWF 22
  861. 0114: MOVLW 77
  862. 0115: MOVWF 23
  863. 0116: MOVLW 20
  864. 0117: MOVWF 24
  865. 0118: MOVLW 63
  866. 0119: MOVWF 25
  867. 011A: MOVLW 61
  868. 011B: MOVWF 26
  869. 011C: MOVLW 6E
  870. 011D: MOVWF 27
  871. 011E: MOVLW 20
  872. 011F: MOVWF 28
  873. 0120: MOVLW 49
  874. 0121: MOVWF 29
  875. 0122: MOVLW 20
  876. 0123: MOVWF 2A
  877. 0124: MOVLW 68
  878. 0125: MOVWF 2B
  879. 0126: MOVLW 65
  880. 0127: MOVWF 2C
  881. 0128: MOVLW 6C
  882. 0129: MOVWF 2D
  883. 012A: MOVLW 70
  884. 012B: MOVWF 2E
  885. 012C: MOVLW 3F
  886. 012D: MOVWF 2F
  887. 012E: CLRF 30
  888. .................... char MESSAGE1[16] = "The answer?";
  889. 012F: MOVLW 54
  890. 0130: MOVWF 31
  891. 0131: MOVLW 68
  892. 0132: MOVWF 32
  893. 0133: MOVLW 65
  894. 0134: MOVWF 33
  895. 0135: MOVLW 20
  896. 0136: MOVWF 34
  897. 0137: MOVLW 61
  898. 0138: MOVWF 35
  899. 0139: MOVLW 6E
  900. 013A: MOVWF 36
  901. 013B: MOVLW 73
  902. 013C: MOVWF 37
  903. 013D: MOVLW 77
  904. 013E: MOVWF 38
  905. 013F: MOVLW 65
  906. 0140: MOVWF 39
  907. 0141: MOVLW 72
  908. 0142: MOVWF 3A
  909. 0143: MOVLW 3F
  910. 0144: MOVWF 3B
  911. 0145: CLRF 3C
  912. 0146: CLRF 3D
  913. 0147: CLRF 3E
  914. 0148: CLRF 3F
  915. 0149: CLRF 40
  916. .................... char MESSAGE2[16] = "Forty Two.";
  917. 014A: MOVLW 46
  918. 014B: MOVWF 41
  919. 014C: MOVLW 6F
  920. 014D: MOVWF 42
  921. 014E: MOVLW 72
  922. 014F: MOVWF 43
  923. 0150: MOVLW 74
  924. 0151: MOVWF 44
  925. 0152: MOVLW 79
  926. 0153: MOVWF 45
  927. 0154: MOVLW 20
  928. 0155: MOVWF 46
  929. 0156: MOVLW 54
  930. 0157: MOVWF 47
  931. 0158: MOVLW 77
  932. 0159: MOVWF 48
  933. 015A: MOVLW 6F
  934. 015B: MOVWF 49
  935. 015C: MOVLW 2E
  936. 015D: MOVWF 4A
  937. 015E: CLRF 4B
  938. 015F: CLRF 4C
  939. 0160: CLRF 4D
  940. 0161: CLRF 4E
  941. 0162: CLRF 4F
  942. 0163: CLRF 50
  943. .................... char MESSAGE3[16] = " ?noitseuQ ehT";
  944. 0164: MOVLW 20
  945. 0165: MOVWF 51
  946. 0166: MOVWF 52
  947. 0167: MOVLW 3F
  948. 0168: MOVWF 53
  949. 0169: MOVLW 6E
  950. 016A: MOVWF 54
  951. 016B: MOVLW 6F
  952. 016C: MOVWF 55
  953. 016D: MOVLW 69
  954. 016E: MOVWF 56
  955. 016F: MOVLW 74
  956. 0170: MOVWF 57
  957. 0171: MOVLW 73
  958. 0172: MOVWF 58
  959. 0173: MOVLW 65
  960. 0174: MOVWF 59
  961. 0175: MOVLW 75
  962. 0176: MOVWF 5A
  963. 0177: MOVLW 51
  964. 0178: MOVWF 5B
  965. 0179: MOVLW 20
  966. 017A: MOVWF 5C
  967. 017B: MOVLW 65
  968. 017C: MOVWF 5D
  969. 017D: MOVLW 68
  970. 017E: MOVWF 5E
  971. 017F: MOVLW 54
  972. 0180: MOVWF 5F
  973. 0181: CLRF 60
  974. .................... //char MESSAGE3[16] = {'T','h','e',' ','q','u','e','s','t','i','o','n','?',' ',' '};
  975. ....................
  976. .................... void send_string(int delay, char string[])
  977. .................... {
  978. .................... int i;
  979. ....................
  980. .................... /* send the string */
  981. .................... for(i=0; string[i] != '\0'; i++)
  982. *
  983. 00F6: CLRF 63
  984. 00F7: MOVF 62,W
  985. 00F8: ADDWF 63,W
  986. 00F9: MOVWF 04
  987. 00FA: MOVF 00,F
  988. 00FB: BTFSC 03.2
  989. 00FC: GOTO 109
  990. .................... {
  991. .................... lcd_putc(string[i]);
  992. 00FD: MOVF 62,W
  993. 00FE: ADDWF 63,W
  994. 00FF: MOVWF 04
  995. 0100: MOVF 00,W
  996. 0101: MOVWF 64
  997. 0102: MOVWF 65
  998. 0103: CALL 0D2
  999. .................... delay_ms(delay);
  1000. 0104: MOVF 61,W
  1001. 0105: MOVWF 6A
  1002. 0106: CALL 01C
  1003. .................... }
  1004. 0107: INCF 63,F
  1005. 0108: GOTO 0F7
  1006. .................... }
  1007. 0109: RETLW 00
  1008. ....................
  1009. .................... void send_string_reverse(int delay, char string[])
  1010. .................... {
  1011. .................... int i;
  1012. ....................
  1013. .................... /* send the string */
  1014. .................... for(i=14; i>=0; i--)
  1015. .................... {
  1016. .................... lcd_putc(string[i]);
  1017. .................... delay_ms(delay);
  1018. .................... }
  1019. .................... }
  1020. ....................
  1021. .................... int main(void)
  1022. 010A: CLRF 04
  1023. 010B: MOVLW 1F
  1024. 010C: ANDWF 03,F
  1025. 010D: MOVLW 07
  1026. 010E: MOVWF 1F
  1027. .................... {
  1028. .................... /* Init the Display */
  1029. .................... lcd_init(2);
  1030. *
  1031. 0182: MOVLW 02
  1032. 0183: MOVWF 61
  1033. 0184: CALL 06D
  1034. .................... /* Clear the screen */
  1035. .................... lcd_putc('\f');
  1036. 0185: MOVLW 0C
  1037. 0186: MOVWF 65
  1038. 0187: CALL 0D2
  1039. .................... /* Send the message */
  1040. .................... send_string(5, INITMESSAGE);
  1041. 0188: MOVLW 05
  1042. 0189: MOVWF 61
  1043. 018A: MOVLW 21
  1044. 018B: MOVWF 62
  1045. 018C: CALL 0F6
  1046. ....................
  1047. .................... /* Display on the first line after button press */
  1048. .................... while(lcd.button == 1)
  1049. .................... { }
  1050. 018D: BTFSC 06.3
  1051. 018E: GOTO 18D
  1052. .................... lcd_putc('\f');
  1053. 018F: MOVLW 0C
  1054. 0190: MOVWF 65
  1055. 0191: CALL 0D2
  1056. .................... send_string(1000, MESSAGE1);
  1057. 0192: MOVLW E8
  1058. 0193: MOVWF 61
  1059. 0194: MOVLW 31
  1060. 0195: MOVWF 62
  1061. 0196: CALL 0F6
  1062. ....................
  1063. .................... while(lcd.button == 1)
  1064. .................... { }
  1065. 0197: BTFSC 06.3
  1066. 0198: GOTO 197
  1067. .................... lcd_putc('\f');
  1068. 0199: MOVLW 0C
  1069. 019A: MOVWF 65
  1070. 019B: CALL 0D2
  1071. .................... /* New line */
  1072. .................... lcd_putc('\n');
  1073. 019C: MOVLW 0A
  1074. 019D: MOVWF 65
  1075. 019E: CALL 0D2
  1076. .................... send_string(5, MESSAGE2);
  1077. 019F: MOVLW 05
  1078. 01A0: MOVWF 61
  1079. 01A1: MOVLW 41
  1080. 01A2: MOVWF 62
  1081. 01A3: CALL 0F6
  1082. .................... /* Add delay for button debouncing */
  1083. .................... delay_ms(500);
  1084. 01A4: MOVLW 02
  1085. 01A5: MOVWF 61
  1086. 01A6: MOVLW FA
  1087. 01A7: MOVWF 6A
  1088. 01A8: CALL 01C
  1089. 01A9: DECFSZ 61,F
  1090. 01AA: GOTO 1A6
  1091. ....................
  1092. .................... /*wait for button press*/
  1093. .................... while(lcd.button == 1)
  1094. .................... { }
  1095. 01AB: BTFSC 06.3
  1096. 01AC: GOTO 1AB
  1097. .................... /* Re-initialise the display to scroll */
  1098. .................... lcd_init(3);
  1099. 01AD: MOVLW 03
  1100. 01AE: MOVWF 61
  1101. 01AF: CALL 06D
  1102. ....................
  1103. .................... while(1) {
  1104. .................... send_string(200, MESSAGE3);
  1105. 01B0: MOVLW C8
  1106. 01B1: MOVWF 61
  1107. 01B2: MOVLW 51
  1108. 01B3: MOVWF 62
  1109. 01B4: CALL 0F6
  1110. .................... /*
  1111. .................... lcd_putc('?');
  1112. .................... delay_ms(200);
  1113. .................... lcd_putc('n');
  1114. .................... delay_ms(200);
  1115. .................... lcd_putc('o');
  1116. .................... delay_ms(200);
  1117. .................... lcd_putc('i');
  1118. .................... delay_ms(200);
  1119. .................... lcd_putc('t');
  1120. .................... delay_ms(200);
  1121. .................... lcd_putc('s');
  1122. .................... delay_ms(200);
  1123. .................... lcd_putc('e');
  1124. .................... delay_ms(200);
  1125. .................... lcd_putc('u');
  1126. .................... delay_ms(200);
  1127. .................... lcd_putc('q');
  1128. .................... delay_ms(200);
  1129. .................... lcd_putc(' ');
  1130. .................... delay_ms(200);
  1131. .................... lcd_putc('e');
  1132. .................... delay_ms(200);
  1133. .................... lcd_putc('h');
  1134. .................... delay_ms(200);
  1135. .................... lcd_putc('T');
  1136. .................... delay_ms(200);
  1137. .................... lcd_putc(' ');
  1138. .................... delay_ms(200);
  1139. .................... */
  1140. .................... }
  1141. 01B5: GOTO 1B0
  1142. ....................
  1143. .................... return 0;
  1144. 01B6: MOVLW 00
  1145. 01B7: MOVWF 78
  1146. .................... }
  1147. 01B8: SLEEP
  1148. Configuration Fuses:
  1149. Word 1: 3F58 NOWDT NOPUT NOPROTECT BROWNOUT NOMCLR NOLVP INTRC_IO NOCPD