根据拨码盘的状态来显示数字。因为拨码盘是7位最多255外数字。所以再主程序转换成要显的字模后显示。
原理图如下:
程序:
- /*
- * GccApplication15.c
- *
- * Created: 2014-10-10 21:55:49
- * Author: Administrator
- */
- #define F_CPU 8000000UL
- #include <avr/io.h>
- #include <util/delay.h>
- #include <stdint.h>
- const int8_t SEG_CODE[] = {0x3F,0x06,0x58,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
- int8_t DSY_Buffer[3] = {0,0,0};
- int main(void)
- {
- while(1)
- {
- uint8_t i,Num;
- DDRC = 0xFF;PORTC = 0xFF;
- DDRB = 0xFF;PORTB = 0xFF;
- DDRD = 0x00;PORTD = 0xFF;
- while(1)
- {
- Num = PINB;
- DSY_Buffer[0] = Num / 100;
- DSY_Buffer[1] = Num /10 % 10;
- DSY_Buffer[2] = Num % 10;
- for(i=0;i<3;i++)
- {
- PORTD = ~_BV(i+1);
- PORTC = SEG_CODE[DSY_Buffer[i]];
- _delay_ms(80);
- }
- }
- }
- }
|