User Tools

Site Tools


archive:nmk322

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
archive:nmk322 [2024/11/12 22:48] – [Library: Keypad] azmanarchive:nmk322 [2024/12/19 11:56] (current) – [Lecture Slides] azman
Line 15: Line 15:
   * Lecture 3 - {{:archive:nmk322:lecture03_c8051.pdf|C for 8051}}   * Lecture 3 - {{:archive:nmk322:lecture03_c8051.pdf|C for 8051}}
   * Lecture 4 - {{:archive:nmk322:lecture04_gpio.pdf|8051 I/O}}   * Lecture 4 - {{:archive:nmk322:lecture04_gpio.pdf|8051 I/O}}
 +  * Lecture 5 - {{:archive:nmk322:lecture05_timer.pdf|8051 Timer}}
 +  * Lecture 6 - {{:archive:nmk322:lecture06_serial.pdf|8051 Serial Interface}}
 +  * Lecture 7 - {{:archive:nmk322:lecture07_interrupt.pdf|8051 Interrupt}}
 +  * Lecture 8 - {{:archive:nmk322:lecture08_system.pdf|8051 System Management}}
  
 ===== Library Codes ===== ===== Library Codes =====
  
 Introduction to using 'library' code. Single header include file(s) meant for single source compilation. These are meant to be compiled using Keil 8051 compiler. Introduction to using 'library' code. Single header include file(s) meant for single source compilation. These are meant to be compiled using Keil 8051 compiler.
 +
 +I recommend to use my include file (mcu51.h) rather than the regular (reg51.h) because it would be easier for you to use my example codes and library. I wrote and tested them using my own syntax that can be used on both Keil and SDCC compilers. Simply extract this {{:archive:nmk322:my1code51inc-20241210.zip|zip file}} and setup the include path. Ask me during lab session if you do not know how to do that.
  
 ==== Library: Serial (UART) ==== ==== Library: Serial (UART) ====
Line 253: Line 259:
 #endif #endif
 #ifndef _ROWS_AT_UPPER_ #ifndef _ROWS_AT_UPPER_
-#define ROWS_FLAG 0x10 
-#define COLS_FLAG 0x01 
-#else 
 #define ROWS_FLAG 0x01 #define ROWS_FLAG 0x01
 #define COLS_FLAG 0x10 #define COLS_FLAG 0x10
 +#else
 +#define ROWS_FLAG 0x10
 +#define COLS_FLAG 0x01
 #endif #endif
  
 /** no-key indicator for keypad */ /** no-key indicator for keypad */
 #define KEY_NOT_CODE 0x10 #define KEY_NOT_CODE 0x10
 +
 +unsigned char key_scan(void) {
 + /** scan for key press */
 + unsigned char irow, icol, mask, test;
 + mask = ROWS_FLAG;
 + for (irow=0;irow<4;irow++) {
 + KEY_DATA = ~mask; test = COLS_FLAG;
 + for (icol=0;icol<4;icol++) {
 + if ((KEY_DATA&test)==0) {
 + while ((KEY_DATA&test)==0);
 + if (icol==3) return irow+0x0A;
 + if (irow==0) return icol+1;
 + if (irow==1) return icol+4;
 + if (irow==2) return icol+7;
 + if (icol==1) return 0;
 + return (icol>>1)+0x0e;
 + }
 + test <<= 1;
 + }
 + mask <<= 1;
 + }
 + return KEY_NOT_CODE;
 +}
 +
 +unsigned char key_wait(void) {
 + /** wait for key press */
 + unsigned char scan;
 + while ((scan=key_scan())==KEY_NOT_CODE);
 + return scan;
 +}
 </file> </file>
  
archive/nmk322.1731422889.txt.gz · Last modified: by azman