Sie sind auf Seite 1von 3

#include <xc.

h>
#define _XTAL_FREQ 4000000
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator: Cry
stal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and c
an be enabled by SWDTEN bit of the WDTCON register)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pi
n function is MCLR)
#pragma config CP = OFF // Code Protection bit (Program memory code prot
ection is disabled)
#pragma config CPD = OFF // Data Code Protection bit (Data memory code pr
otection is disabled)
#pragma config BOREN = ON // Brown Out Reset Selection bits (BOR enabled)
#pragma config IESO = ON // Internal External Switchover bit (Internal/Ex
ternal Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enabled bit (Fail-Saf
e Clock Monitor is enabled)
#pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin h
as digital I/O, HV on MCLR must be used for programming)
#pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Rese
t set to 4.0V)
#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (
Write protection off)
int j;
int k;
int cuenta;
int repeticiones=10;
int display1[10]={0b10000001,0b10000001,0b10000001,0b10000001,0b10000001,0b10000
001,0b10000001,0b10000001,0b10000001,0b10000001};
int display2[10]={0b10010001,0b00011101,0b10010001,0b00011101,0b10010001,0b00011
101,0b10010001,0b00011101,0b10010001,0b00011101};
int display3[10]={0b11111111,0b00011101,0b11111111,0b00011101,0b11111111,0b00011
101,0b11111111,0b00011101,0b11111111,0b00011101};
int display4[10]={0b10000001,0b11110011,0b01001001,0b01100001,0b00110011,0b00100
101,0b00000101,0b11110001,0b00000001,0b00110001};
void main(void)
{
ANSEL=0;
ANSELH=0;
TRISA=0;
TRISAbits.TRISA0=1;
TRISAbits.TRISA5=0;
TRISB=0;
PORTA=0;
PORTB=0b11111111;
while(j<=9)
{ if(PORTAbits.RA0==1)
{
PORTB=display4[cuenta];
}
else
{
__delay_ms(50);
cuenta++;
if(cuenta>9)
{
cuenta=0;
}
}
for(k=0; k<repeticiones; k++)
{
PORTAbits.RA1=1;
PORTB=display1[cuenta];
__delay_ms(5);
PORTAbits.RA1=0;
PORTAbits.RA2=1;
PORTB=display2[cuenta];
__delay_ms(5);
PORTAbits.RA2=0;
PORTAbits.RA3=1;
PORTB=display3[cuenta];
__delay_ms(5);
PORTAbits.RA3=0;
PORTAbits.RA4=1;
PORTB=display4[cuenta];
__delay_ms(5);
PORTAbits.RA4=0;
}
if(cuenta==0)
{
PORTAbits.RA5=1;
}
if(cuenta==1)
{
PORTAbits.RA5=0;
}
if(cuenta==2)
{
PORTAbits.RA5=1;
}
if(cuenta==3)
{
PORTAbits.RA5=0;
}
if(cuenta==4)
{
PORTAbits.RA5=1;
}
if(cuenta==5)
{
PORTAbits.RA5=0;
}
if(cuenta==6)
{
PORTAbits.RA5=1;
}
if(cuenta==7)
{
PORTAbits.RA5=0;
}
if(cuenta==8)
{
PORTAbits.RA5=1;
}
if(cuenta==9)
{
PORTAbits.RA5=0;
}
}
j++;
cuenta++;
if(cuenta>9)
{
cuenta=0;
}
return;
}

Das könnte Ihnen auch gefallen