PIC16F877A单片机数码管数值循环显示设计
原标题:PIC16F877A单片机数码管数值循环显示设计
//数码管显示
//★★★★★★★★★数码管显示★★★★★★★★★★★
//单征机型号:PIC16F877A
//功能描述:采用动态扫描方式,初始时显示123,当按下RB0时,数值加一,当按下RB1时,数值减一
//端口定义:RA0,RA1,RA2数码管位控制脚,RD口数码管段控制口,RB0加一按键,RB1减一按键。
#include
__CONFIG(0XF73A); //芯片配置字节
const unsigned char disp[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//0~9译码
char ba,sh,ge,keyb0,keyb1;
void dir();
void key();
//========================================================================
//功能描述:延时子程序
//函数名称:delay);
void delay()
{
int i;
for(i=200;i》0;i--);
}
//========================================================================
//功能描述:主程序
//函数名称:void main()
void main()
{
keyb0=0;
ba=1;
sh=2;
ge=3;
TRISA=0x00;
TRISD=0x00;
PORTA=0xff;
while(1)
{
key();
dir();
}
}
//========================================================================
//功能描述:判断按键程序
//函数名称:void key()
void key()
{
//------------------------------------------------------------------------
//判断RB0键是否作用,进行加一操作
if(RB0==0)
{
delay();
if(RB0==0)
{
if(keyb0==0)
{
keyb0=1;
ge++;
if(ge==10)
{
ge=0;
sh++;
if(sh==10)
{
sh=0;
ba++;
if(ba==10)
{ba=0;}
}
}
}
}
}
else keyb0=0;
//------------------------------------------------------------------------
//判断RB1键是否作用,进行减一操作
if(RB1==0)
{
delay();
if(RB1==0)
{
if(keyb1==0)
{
keyb1=1;
ge--;
if(ge==255)
{
ge=9;
sh--;
if(sh==255)
{
sh=9;
ba--;
if(ba==255)
ba=9;
}
}
}
}
}
else keyb1=0;
}
//========================================================================
//功能描述:显示程序
//函数名称:void dir()
void dir()
{
PORTA=0xfb; //选中个位数码管
PORTD=disp[ge]; //往个位数码管送数
delay(); //延时一段时间,保证亮度
PORTA=0xfd;
PORTD=disp[sh];
delay();
PORTA=0xfe;
PORTD=disp[ba];
delay();
}
【PIC16F877A】
Features:
2 PWM 10-bit 256 Bytes EEPROM data memory ICD 25mA sink/source per I/O Self Programming Parallel Slave Port
Device Overview
Summary
This powerful (200 nanosecond instruction execution) yet easy-to-program (only 35 single word instructions) CMOS FLASH-based 8-bit microcontroller packs Microchip's powerful PIC® architecture into an 40- or 44-pin package and is upwards compatible with the PIC16C5X, PIC12CXXX and PIC16C7X devices. The PIC16F877A features 256 bytes of EEPROM data memory, self programming, an ICD, 2 Comparators, 8 channels of 10-bit Analog-to-Digital (A/D) converter, 2 capture/compare/PWM functions, the synchronous serial port can be configured as either 3-wire Serial Peripheral Interface (SPI™) or the 2-wire Inter-Integrated Circuit (I²C™) bus and a Universal Asynchronous Receiver Transmitter (USART). All of these features make it ideal for more advanced level A/D applications in automotive, industrial, appliances and consumer applications.
Please consider this device PIC16F18877
Additional Features:2 PWM 10-bit
256 Bytes EEPROM data memory:ICD
25mA sink/source per I/O:Self Programming
Parallel Slave Port:Parametrics
Name:Value
Program Memory Type:Flash
Program Memory Size (KB):14
CPU Speed (MIPS/DMIPS):5
SRAM Bytes:368
Data EEPROM/HEF (bytes):256
Digital Communication Peripherals:1-UART, 1-SPI, 1-I2C1-MSSP(SPI/I2C)
Capture/Compare/PWM Peripherals:2 Input Capture, 2 CCP,
Timers:2 x 8-bit, 1 x 16-bit
ADC Input:8 ch, 10-bit
Number of Comparators:2
Temperature Range (C):-40 to 125
Operating Voltage Range (V):2 to 5.5
Pin Count:40
责任编辑:David
【免责声明】
1、本文内容、数据、图表等来源于网络引用或其他公开资料,版权归属原作者、原发表出处。若版权所有方对本文的引用持有异议,请联系拍明芯城(marketing@iczoom.com),本方将及时处理。
2、本文的引用仅供读者交流学习使用,不涉及商业目的。
3、本文内容仅代表作者观点,拍明芯城不对内容的准确性、可靠性或完整性提供明示或暗示的保证。读者阅读本文后做出的决定或行为,是基于自主意愿和独立判断做出的,请读者明确相关结果。
4、如需转载本方拥有版权的文章,请联系拍明芯城(marketing@iczoom.com)注明“转载原因”。未经允许私自转载拍明芯城将保留追究其法律责任的权利。
拍明芯城拥有对此声明的最终解释权。