Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

display problem with pic18f4520

Status
Not open for further replies.

pany_pat

New Member
#include <htc.h>
#include <pic18.h>

__CONFIG(1, INTIO & FCMDIS & IESODIS); // internal oscillator config bit set
__CONFIG(2, PWRTDIS & BORDIS & WDTDIS); // power reset timer, bor & watch dog timer disable config bit set
__CONFIG(3, MCLRDIS); // MCLR disable and can be used as RE pin config bit set

unsigned char eeprom_counter,serial_in,serial_out,nop;
unsigned char dummy,dummy1,ii,digit[9],disp_no;

extern ser_in_out(),shout(),shin();
extern init_ports(),init();
void DelayMS(unsigned int);

const char SSEG[] = {
0b11000000, // 0, LED Segment: A,B,C,D,E,F
0b11111001, // 1, LED Segment: B,C
0b10100100, // 2, LED Segment: A,B,D,E,G
0b10110000, // 3, LED Segment: A,B,C,D,G
0b10011001, // 4, LED Segment: B,C,F,G
0b10010010, // 5, LED Segment: A,C,D,F,G
0b10000010, // 6, LED Segment: A,C,D,E,F,G
0b11111000, // 7, LED Segment: A,B,C
0b10000000, // 8, LED Segment: A,B,C,D,E,F,G
0b10010000, // 9, LED Segment: A,B,C,D,F,G
0b11000110, // C, LED Segment: A,D,E,F
0b10001110 // F, LED Segment: A,E,F,G
};


void main()
{
init(); // oscillator & Timer initialized

init_ports(); // port i/o initialized

serial_out = 0xff;
shout();
dummy1 = dummy = 0;

for(;;)
{
GIE = 1;
}
}

void DelayMS(unsigned int itime)
{
unsigned int i;
unsigned char j;
for(i=0;i<itime;i++)
for(j=0;j<165;j++);
}

init()
{
OSCTUNE = 0x40; // PLL to clk * 4 32mhz system clock
PSA = 1;
T0CON = 0b10001101;
TMR0IF = 0;
TMR0IE = 1;
GIE = 1;

OSCCON=0x70; /* Select 8 Mhz internal clock */

/* Init TIMER0: Period: 1/(Fosc/4) x Prescaler x TMR0
0.0005 ms x 64 * 100 = 3.2 ms */

TMR0=156; // Interupt every 3.2 ms

GIE = 1; // Global interrupt enable

}

init_ports()
{
T_LED = 0; // pin enable to output
LED = 1;
T_SCLIO = 0; // pin enable to output
SCLIO = 0;
T_SDI = 1; // pin enable to input
SDI = 0;
T_SDO = 0; // pin enable to output
SDO = 0;
T_CP = 0; // pin enable to output
CP = 0;
T_SHF = 0; // pin enable to output
SHF = 0;
PORTD = 0x00;
TRISD = 0x00;
T_D0 = 0; // pin enable to output for digit drive
D0 = 0;
T_D1 = 0; // pin enable to output for digit drive
D1 = 0;
T_D2 = 0; // pin enable to output for digit drive
D2 = 0;
}

shout() // Serial data out
{
CP = 0;
SCLIO = 0; // serial clock low
for (ii=0; ii<8; ii++)
{ //send 8 bits
if ((serial_out & 0x01)==1) SDO = 1;
else SDO =0;
SCLIO = 1;
serial_out >>=1;
SCLIO = 0;
}
SCLIO = 0;
CP = 1;
++nop;
++nop;
CP = 0;
}

shin() // Serial Data In from 74hc165
{
unsigned char i;
unsigned char datas = 0;

SHF = 1;
DelayMS(1);
SCLIO = 0;
DelayMS(1);
SHF = 0;
DelayMS(1);
SHF = 1;
DelayMS(1);
for(i = 0; i < 8; i++)
{
CARRY = SDI;
//LED = ~SDI;
if(CARRY) datas = datas | 0x01;
datas = datas << 1;
SCLIO = 1;
DelayMS(10);
SCLIO = 0;
}
SCLIO = 0;
serial_in = datas;
}


void interrupt ISR()
{
if(TMR0IF)
{
if(disp_no == 0)
{
D0 = 0;
D1 = 0;
D2 = 0;
PORTD = SSEG[digit[0]];
}
else if(disp_no == 1)
{
D0 = 1;
D1 = 0;
D2 = 0;
PORTD = SSEG[digit[1]];
}
else if(disp_no == 2)
{
D0 = 0;
D1 = 1;
D2 = 0;
PORTD = SSEG[digit[2]];
}
else if(disp_no == 3)
{
D0 = 1;
D1 = 1;
D2 = 0;
PORTD = SSEG[digit[3]];
}
else if(disp_no == 4)
{
D0 = 0;
D1 = 0;
D2 = 1;
PORTD = SSEG[digit[4]];
}
else if(disp_no == 5)
{
D0 = 1;
D1 = 0;
D2 = 1;
PORTD = SSEG[digit[5]];
}
else if(disp_no == 6)
{
D0 = 0;
D1 = 1;
D2 = 1;
PORTD = SSEG[digit[6]];
}
else if(disp_no == 7)
{
D0 = 1;
D1 = 1;
D2 = 1;
PORTD = SSEG[digit[7]];
}
disp_no++;
if (disp_no >= 8) disp_no = 0;
shin();
serial_out = serial_in;
shout();
digit[0] = 1;
digit[1] = 2;
digit[2] = 3;
digit[3] = 4;
digit[4] = 5;
digit[5] = 6;
digit[6] = 7;
digit[7] = 8;
TMR0 = 156; // Initial Value for 3.2 ms Interrupt
TMR0IF = 0; // Clear TIMER0 interrupt flag
}
}

#ifndef BITNUM
#define BITNUM(adr, bit) ((unsigned)(&adr)*8+(bit)) //-- used for port defs
#endif

static bit CP @ BITNUM(PORTC,0); //-- CP - 74HC273
static bit T_CP @ BITNUM(TRISC,0);
static bit SHF @ BITNUM(PORTC,1); //-- SHF/LD - 74HC165
static bit T_SHF @ BITNUM(TRISC,1);
static bit LED @ BITNUM(PORTC,2); //-- LED
static bit T_LED @ BITNUM(TRISC,2);
static bit SCLIO @ BITNUM(PORTC,3); //-- Serial Clock For Input & Output
static bit T_SCLIO @ BITNUM(TRISC,3);
static bit SDI @ BITNUM(PORTC,4); //-- Serial Data Input
static bit T_SDI @ BITNUM(TRISC,4);
static bit SDO @ BITNUM(PORTC,5); //-- Serial Data Output
static bit T_SDO @ BITNUM(TRISC,5);

static bit D0 @ BITNUM(PORTA,4); //-- Card Register Address 0
static bit T_D0 @ BITNUM(TRISA,4);
static bit D1 @ BITNUM(PORTA,6); //-- Card Register Address 1
static bit T_D1 @ BITNUM(TRISA,6);
static bit D2 @ BITNUM(PORTA,7); //-- Card Register Address 2
static bit T_D2 @ BITNUM(TRISA,7);

hi to every one here, i very new to pic programming, i have just started doing project on pic microcontroller based till now i was doing the 89c52 based project.

here i have posted the c code of my project i am using picc18 compiler for project, i am having problem with display
section,
current software is for 8 digit seven segment display digit selection is done by 74hc138, G2( A&B) is permanently low, G1 is high,

1) no value is displayed on the display just all segment get on,
2) display digit scan is not fast it just get waves type it scanning very slow out,
3) data input error in shin() routine

i am able to understand that digit scanning is slow due to no proper handling of timer0, but not able to understand why no value is displayed on any digit,

please guide where i have made some major or minor mistake in the program.
 
Status
Not open for further replies.

Latest threads

Back
Top