- #include"sys.h"
- #include <stdint.h>
- #include <stdbool.h>
- #include <stdio.h>
- uint8_t disp_buff=0;
- #define LED_OUTPUT PORTD
- uint8_t i=0;
- uint8_t disp_tabA[8]={0b0000000,0b10000001,0b11000011,0b11100111,0b11111111};
- void main()
- {
- TRISD=0;
- LED_OUTPUT=0;
- while(1)
- {
- for(i=0;i<8;i++)
- {
- disp_buff=(uint8_t)((disp_buff<<1)+1); //右移加1 实现逐个点亮
- LED_OUTPUT=disp_buff;
- __delay_ms(500);
- }
- for(i=0;i<8;i++)
- {
- disp_buff=(uint8_t)(disp_buff>>1); //左移,实现逐个灭灯
- LED_OUTPUT=disp_buff;
- __delay_ms(500);
- }
- for(i=0;i<5;i++)
- {
- LED_OUTPUT=disp_tabA[i]; //由disp_tabA[0]---disp_tabA[5]依次旁边向中间点亮
- __delay_ms(500);
- }
- for(i=0;i<5;i++)
- {
- LED_OUTPUT=disp_tabA[(uint8_t)(4-i)]; //由disp_tabA[5]---disp_tabA[0]依次旁边向中间到两边逐渐灭灯
- __delay_ms(500);
- }
-
- }
- }
复制代码
- // PIC16F887 Configuration Bit Settings
- // 'C' source line config statements
- // CONFIG1
- #pragma config FOSC = INTRC_NOCLKOUT// Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function on RA7/OSC1/CLKIN)
- #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register)
- #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
- #pragma config MCLRE = OFF // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD)
- #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled)
- #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled)
- #pragma config BOREN = ON // Brown Out Reset Selection bits (BOR enabled)
- #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled)
- #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled)
- #pragma config LVP = ON // Low Voltage Programming Enable bit (RB3/PGM pin has PGM function, low voltage programming enabled)
- // CONFIG2
- #pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
- #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)
- // #pragma config statements should precede project file includes.
- // Use project enums instead of #define for ON and OFF.
- #include <xc.h>
- #define _XTAL_FREQ 16000000
复制代码 |