florisvd 0 Newbie Poster

Hello,

I'm making a scoreboard and I'm using multiplexing 7 segments.
With a remote control I'm controlling the counting of the digits.
I have two big problems with this.
The first is that I can count just 2 times by sending b to the UDR.
After that I have to send something else to count up.

How can I fix that I can count up two 199?

The second problem is that if I'm trying to count up with two 7 segment seperaterly I can count up 1 time, and then I need to count up the other 7 segment.

How to fix this?

Under this is my code:

/********************************************************************************
Includes
********************************************************************************/
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
 
/********************************************************************************
             Defines
********************************************************************************/
#define USART_BAUDRATE 9600 
#define BAUD_PRESCALE 51 
/********************************************************************************
             Functies
********************************************************************************/

/********************************************************************************
             usart
********************************************************************************/


uint8_t UART_receive(void) //uart ontvangen
{ 
  
  while (!(UCSRA | (1<<RXC))); 
  return UDR; 
 
} 







/********************************************************************************
Main
********************************************************************************/
 
int main (void) 
{ 
  
   UCSRB |= (1 << RXEN) | (1 << TXEN);   //zend en ontvang
   UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // 8 bit

   UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register 
   UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register 
 
int numbers[10]=
	{0b01000000,		// 0
	0b11111001,		// 1
	0b00100100,		//2
	0b10110000,		// 3
	0b00011001,		// 4
	0b10010010,		// 5
//	0b00000011,		// 6
	0b00000010,		// 6 
	0b11111000,		// 7
	0b00000000,		// 8
//	0b10011000,		// 9 
	0b10010000	};
int i=0;
int j=0;


DDRA=0xFF;
DDRB=0xFF;
DDRC=0xFF;										    /* Pull-ups enabled */
PORTA=0x00;
PORTB=numbers[0];
PORTC=0x00;
 
 unsigned char data;	
 char b,a;
 
 
 	while (1) 
	 { 
  		PORTC=(~(0x01));
		PORTB=numbers[i];
		_delay_ms(1);
		PORTC=(~(0x02));
		PORTB=numbers[j];
		_delay_ms(1);
		
		
 		 if (!('b' == UART_receive()))
  		 {
		 	i++;	 
				  
   		 		PORTC=(~(0x01));
				PORTB=numbers[i];
				_delay_ms(1);
				PORTC=(~(0x02));
				PORTB=numbers[j];
				_delay_ms(1);
		 	while (!('b'== UART_receive()))
		 	{
				
 				PORTC=(~(0x01));
				PORTB=numbers[i];
				_delay_ms(1);
				PORTC=(~(0x02));
				PORTB=numbers[j];
				_delay_ms(1);
	
			}
		}
		 	
		if (!('c' ==  UART_receive()))
		{
			j++;
			while (!('c' == UART_receive()))
			{
				PORTC=(~(0x01));
				PORTB=numbers[i];
				_delay_ms(1);
				PORTC=(~(0x02));
				PORTB=numbers[j];
				_delay_ms(1);
			}
		}	
		 
		  
	

  									   		   
 	} 
}

best regards,
Floris