|
09-05-2006, 09:18 PM | #1 |
Đệ tử 1 túi
Tham gia ngày: Apr 2006
Bài gửi: 16
: |
Chương trình hiển thị phím số ra đèn 7 đoạn (không dùng interrupt)
Code:
Chương trình hiển thị phím số trên ma trận phím 4x3 ra đèn 7 đoạn (không dùng interrupt) #include <16F877A.h> #fuses NOWDT, XT #fuses NOLVP // important #use delay(clock=4000000) #include <kbd.c> // in PICC\Drivers // 0 1 2 3 4 5 6 7 8 9 byte const DIGITS[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f }; /////////////////////////////////////////////////////////// /* private */void off_on_led_transistor() { output_low(PIN_D1); delay_ms(1); output_high(PIN_D1); } /////////////////////////////////////////////////////////// void display(int8 digit) { output_c(DIGITS[digit] ^ 0xff); off_on_led_transistor(); } /////////////////////////////////////////////////////////// int8 char_to_digit(char c) { return c & 0b00001111; // first 4 bits only } /////////////////////////////////////////////////////////// int1 digit_key_pressed(char key) { byte pattern; pattern = 0b00110000; return (key & pattern) == pattern; } /////////////////////////////////////////////////////////// /** * Echo digit-key presses (0 to 9) of a 4x3 keypad to the 7-segment LED * * Configuration: * Use PORTB for keypad by uncommenting the following line in PICC\Drivers\KBDD.c * #define use_portb_kbd TRUE * * Wiring: (TM Board) * (1) PIC's B1-B7 to Matrix Keypad's R3-R0&C2-C0 (notice the reverse order) * (2) PIC's C0-C6 to 7-segment LED's A-G * PIC's D1 to 7-segment LED's C2 */ void main() { int8 i, digit; char key; kbd_init(); while (true) { key = kbd_getc(); if (digit_key_pressed(key)) { digit = char_to_digit(key); for (i = 0; i < 200; i++) // repeat the display for human eyes display(digit); } } } thay đổi nội dung bởi: falleaf, 12-05-2006 lúc 09:01 PM. |
|
|
Similar Threads | ||||
Ðề tài | Người gửi | Chuyên mục | Trả lời | Bài mới |
TUT ve I2C ( pic16f877a ) | mafd_47a | MPASM | 26 | 07-05-2024 08:55 AM |
TUT về USART trong PIC16F877A | mafd_47a | MPASM | 11 | 04-05-2024 04:43 AM |
Lập nhóm PIC16F877A | nhh | Cơ bản về vi điều khiển và PIC | 285 | 08-03-2017 11:08 PM |
Bộ so sánh và PWM cho PIC16F877A | anhquangngai | Cơ bản về vi điều khiển và PIC | 24 | 08-09-2012 09:00 AM |
Pic16f877a TỪ DỄ TỚi KhÓ | ntc | Cơ bản về vi điều khiển và PIC | 373 | 23-05-2009 10:24 PM |