archive:nmk322
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| archive:nmk322 [2024/11/04 12:23] – [Library: Timer] azman | archive:nmk322 [2025/10/01 07:31] (current) – [Lecture Slides] azman | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| [20241017] Updating this for 202425s1 Academic Session. | [20241017] Updating this for 202425s1 Academic Session. | ||
| - | ===== Lecture Slides ===== | ||
| - | * Lecture 1 - {{: | + | ===== Library |
| - | * Lecture 2 - {{: | + | |
| - | + | ||
| - | ===== Codes (discussed in class) | + | |
| Introduction to using ' | Introduction to using ' | ||
| + | |||
| + | 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 {{: | ||
| + | |||
| ==== Library: Serial (UART) ==== | ==== Library: Serial (UART) ==== | ||
| Line 234: | Line 233: | ||
| #endif /** __MY1UTILS_H__ */ | #endif /** __MY1UTILS_H__ */ | ||
| + | </ | ||
| + | |||
| + | ==== Library: Keypad ==== | ||
| + | |||
| + | <file c kpad.h> | ||
| + | #ifndef __MY1KPAD_H__ | ||
| + | #define __MY1KPAD_H__ | ||
| + | |||
| + | /* 4x4 keypad interface {R0, | ||
| + | /* 4x3 keypad interface {C1, | ||
| + | |||
| + | /** DefaultPins: | ||
| + | #ifndef KEY_DATA | ||
| + | #define KEY_DATA P1 | ||
| + | #endif | ||
| + | #ifndef _ROWS_AT_UPPER_ | ||
| + | #define ROWS_FLAG 0x01 | ||
| + | #define COLS_FLAG 0x10 | ||
| + | #else | ||
| + | #define ROWS_FLAG 0x10 | ||
| + | #define COLS_FLAG 0x01 | ||
| + | #endif | ||
| + | |||
| + | /** no-key indicator for keypad */ | ||
| + | #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; | ||
| + | KEY_DATA = ~mask; test = COLS_FLAG; | ||
| + | for (icol=0; | ||
| + | if ((KEY_DATA& | ||
| + | while ((KEY_DATA& | ||
| + | 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>> | ||
| + | } | ||
| + | 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; | ||
| + | } | ||
| </ | </ | ||
archive/nmk322.1730694224.txt.gz · Last modified: by azman
