Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

http://infoldersoft.

com/basic-spi-communication-between-two-pic-microcontrollers
/
http://www.circuitvalley.com/2011/08/microchip-spi-basics-tutorial-for-pic18.htm
l
http://www.vincenzov.net/tutorial/PIC18/SPI.htm

/*
* Project name:
Decimal UP Counter with Four 7-Segment Display Multiplexing
* Copyright:
(c) Rajendra Bhatt, 2011.
* Description:
This code is an example of multiplexed Seven Segment Displays.
MCU: PIC16F628A, 4.0 MHz external clock, MCLR Enabled
The common anodes of four seven segment dispalys are
connected to RA0, RA1, RA2 and RA3, whereas the seven
segments are driven through PORTB pins
*/
unsigned short i, DD0, DD1, DD2, DD3;
unsigned int Count;
//------ Function to Return mask for common anode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0xC0;
case 1 : return 0xF9;
case 2 : return 0xA4;
case 3 : return 0xB0;
case 4 : return 0x99;
case 5 : return 0x92;
case 6 : return 0x82;
case 7 : return 0xF8;
case 8 : return 0x80;
case 9 : return 0x90;
} //case end
}
void main() {
CMCON |= 7;
// Disable Comparators
TRISB = 0x00; // Set PORTB direction to be output
PORTB = 0xff;
// Turn OFF LEDs on PORTB
TRISA = 0b00100000; // RA5 is input only
Count =
0; // Initial Value of Counter
do {
DD0 =
DD0 =
DD1 =
DD1 =
DD2 =
DD2 =
DD3 =
DD3 =

Count%10; // Extract Ones Digit


mask(DD0);
(Count/10)%10; // Extract Tens Digit
mask(DD1);
(Count/100)%10; // Extract Hundreds Digit
mask(DD2);
(Count/1000); // Extract Thousands Digit
mask(DD3);

for (i = 0; i<=50; i++) {


PORTB = DD0;

RA0_bit = 0;
// Select Ones Digit
RA1_bit = 1;
RA2_bit = 1;
RA3_bit = 1;
delay_ms(5);
PORTB = DD1;
RA0_bit = 1;
RA1_bit = 0;
// Select Tens Digit
RA2_bit = 1;
RA3_bit = 1;
delay_ms(5);
PORTB = DD2;
RA0_bit = 1;
RA1_bit = 1;
RA2_bit = 0;
// Select Hundreds Digit
RA3_bit = 1;
delay_ms(5);
PORTB = DD3;
RA0_bit = 1;
RA1_bit = 1;
RA2_bit = 1;
RA3_bit = 0;
// Select Thousands Digit
delay_ms(5);
}
Count = Count + 1 ;
if (Count > 9999) Count = 0;
} while(1);
// endless loop
}

You might also like