Per comandare quale posizione dei display si deve agire sulla porta A. Per esempio impostando la maschera dei bit della porta A a 0xFD si attiva il secondo posto da sinistra (maschera 11111101) mentre con 0xDF si attiva il 6° posto da sinistra (maschera 11011111)
Impostando la porta D si decide quale carattere mostrare
Questo e' il programma
-----------------------------------
#include <xc.h>
// CONFIG
#pragma config FOSC = XT // Oscillator Selection bits (XT oscillator)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
const unsigned char LED[]=
{
0xc0,0xf9,0xa4,0xb0,//0~3
0x99,0x92,0x82,0xf8,//4~7
0x80,0x90,0x88,0x83,//8~b
0xc6,0xa1,0x86,0x8e //c~f
};
void delay(unsigned int count);
void main(void)
{
unsigned int i;
TRISA&=0XFD;
TRISD=0B00000000;
PORTD=0xFF;
PORTA=0XFD;
while(1)
{
for(i=0;i<16;i++)
{
PORTD=LED[i];
delay(30);
}
}
}
void delay(unsigned int count)
{
unsigned int a,i;
for(i=0;i<count;i++)
{
for(a=0;a<5000;a++)
asm("NOP");
}
}
-----------------------------------
Nessun commento:
Posta un commento