Help Urgent -- please check my uC code.

Thread Starter

Sharik

Joined Oct 12, 2015
1
can someone please chek my code i just cant figure it out with the display when i run the program the numbers doesnt show correctly on my display

C:
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#include <avr/interrupt.h>
#include <stdbool.h>

int mode;
int counter = 0;
int counters = 0;
int freq = 0;
int interruptcount = 0;
int screen [4] = {11, 11, 11, 11}; // everything off
int setpoint = 10;
int direction = 0;

const unsigned char cijfers[] =
{
0x82, // 1000 0010 = 0
0xBB, // 1001 1111 = 1
0x85, // 1000 0101 = 2
0x91, // 1001 0001 = 3
0xB8, // 1101 1000 = 4
0xD0, // 1101 0000 = 5
0xC0, // 1100 0000 = 6
0x9B, // 1001 1011 = 7
0x80, // 1000 0000 = 8
0x90, // 1000 1000 = 9
0x00, // 0000 0000 = Everything ON
0xFF // 1111 1111 = Everything OFF
};

ISR(INT0_vect)
{
if(setpoint >= 90)
{
setpoint = 10;
}
else
{
setpoint += 10;
}
}
ISR(TIMER0_OVF_vect)
{
TCNT0 = 133;//
if (++interruptcount == 500)
{
if(counter == setpoint)
{
direction = 1;
}
else if(counter == 0)
{
direction = 0;
}
if (direction == 1)
{
counter--;
}
else
{
counter++;
}
interruptcount = 0;// reset counters
counters = 0;
}
}
int main(void)
{
TCCR0 = _BV(CS01);// de prescaling is 8
TCNT0 = 135;// start timer with 135
TIMSK = _BV(TOIE0);// interrupt timer0 overflow
GICR = _BV(INT0);// enable externe interrupt bit INT0
MCUCR = _BV(ISC01 || ISC00);// neergaande flank ISC01=1 ISC00=0
DDRA = 0xFF; // display
DDRB = 0xFF; // 7 segmeten display
DDRD = 0x00; //
int multiplexer = 0x01;
sei();// zet interrupt flag

while(1)
{
setScreen(counter);// setscreen functie

//multiplexen of the  4 segmenten
for(int i = 3; i >= 0; i--)
{
PORTA = 0x7F-(multiplexer);
PORTB = cijfers[screen[I]];
_delay_ms(2);
multiplexer = multiplexer*2;
}
multiplexer = 0x01;
PORTA = 0x77;
PORTB = cijfers[setpoint/10];
_delay_ms(1);
PORTA = 0x7B;
PORTB = cijfers[0];
_delay_ms(1);
}
}
void setScreen(int number)
{
if(number <= 9)
{
screen[0] = 11;
screen[1] = 11;
screen[2] = 11;
screen[3] = number;
}
else if(number <= 99)
{
screen[0] = 11;
screen[1] = 11;
screen[2] = (number /10) %10;
screen[3] = number % 10;
}
else if(number <= 999)
{
screen[0] = 11;
screen[1] = (number / 100) %10;
screen[2] = (number /10) %10;
screen[3] = number % 10;
}
else
{
screen[0] = (number / 1000) % 10;
screen[1] = (number / 100) % 10;
screen[2] = (number / 10) % 10;
screen[3] = number % 10;
}
}
Moderators note: used code tags
 
Last edited by a moderator:

Andreas

Joined Jan 26, 2009
90
Is that C++ with a bit of Assembly thrown in?
Which AVR mC are you programming?

I can't help you directly, but indirectly I can tell you that (for a start) you may want to be more descriptive with your subject line if you want other people to help you. A better lay out of your code and more comments can only help too. You may want to rethink and rewrite your main description and objectives. What you hope to achieve and the problems you are experiencing.

Best of luck.
 

JohnInTX

Joined Jun 26, 2012
4,787
Assuming a typical hookup (schematic please):
Recheck your logic at line 89 (PORTA = 0x7F-(multiplexer) It does not rotate the single bit digit select like you want.
Also, both the segment outputs and digit outputs appear to be active low. Unless you are using external drivers, that won't work.
As @ScottWang says, a schematic is necessary to do much more.
What SPECIFICALLY is the display showing when it should SPECIFICALLY show something else?

Edit: Welcome to AAC! Here you will find many people able and willing to help you if you provide the requested information.
 
Last edited:
Top