venkates2218
Full Member level 6
Code:
#define XTAL_FREQ 20MHZ /* Crystal frequency in MHz */
#include <pic.h>
#include <xc.h>
#include "delay.h"
// CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//VARIABLE INITIALION
int a0[7] = {0, 1, 1, 1, 1, 1, 1};
int a1[7] = {0, 0, 0, 0, 1, 1, 0};
int a2[7] = {1, 0, 1, 1, 0, 1, 1};
int a3[7] = {1, 0, 0, 1, 1, 1, 1};
int a4[7] = {1, 1, 0, 0, 1, 1, 0};
int a5[7] = {1, 1, 0, 1, 1, 0, 1};
int a6[7] = {1, 1, 1, 1, 1, 0, 1};
int a7[7] = {0, 0, 0, 0, 1, 1, 1};
int a8[7] = {1, 1, 1, 1, 1, 1, 1};
int a9[7] = {1, 1, 0, 1, 1, 1, 1};
void System_init(void) {
TRISA = 0X00;
PORTA = 0X00;
CMCON = 0X07;
TRISB = 0b00000000;
PORTB = 0b00000000;
}
/**************************************************************
Main Program
**************************************************************/
void main(void) {
System_init();
while (1) {
RB2 = 1;
RB3 = 0;
for (int i = 0; i < 7; i++) {
RB1 = 1;
RB0 = a0[i];
RB1 = 0;
DelayMs(10);
}
RB2 = 0;
RB3 = 1;
for (int i = 0; i < 7; i++) {
RB1 = 1;
RB0 = a1[i];
RB1 = 0;
DelayMs(10);
}
}
}
Please refer the circuit image.
This is my circuit and programmed this program to display the number 7 segment display....
I can get the output but I can see the bits shifting while trying to display the numbers.
Is any error in program or circuit..?
Last edited by a moderator: