I am simulating a project in Proteus where I show a three-digit number (456) on a 7-segment display, but instead of showing 456 it shows 006.......... the calculations are well done but I can't figure out where is the problem.
here diagram
7 seg display electric diagram
here code
/* Main.c file generated by New Project wizard
*
* Created: mi. ene. 10 2024
* Processor: PIC16F84A
* Compiler: CCS for PIC
*/
#include <16F84a.h>
#fuses NOWDT
#use delay(clock=4000000)
#define UNO 0x0C // 00001100
#define DOS 0xB6 // 10110110
#define TRES 0x9E // 10011110
#define CUATRO 0xCC // 11001100
#define CINCO 0xDA // 11011010
#define SEIS 0xFA // 11111010
#define SIETE 0x0E // 00001110
#define OCHO 0xFE // 11111110
#define NUEVE 0xCE // 11001110
#define CERO 0x7E // 01111110
#define ERROR 0b11110010
#define U 0x1
#define D 0x2
#define C 0x4
byte mostrar(int index){
switch(index) {
case 0: return CERO;
case 1: return UNO;
case 2: return DOS;
case 3: return TRES;
case 4: return CUATRO;
case 5: return CINCO;
case 6: return SEIS;
case 7: return SIETE;
case 8: return OCHO;
case 9: return NUEVE;
default: return ERROR; // Manejar casos no definidos
}
}
int main (void)
{
set_tris_a(0x00); // Configura todos los pines del Puerto A como salida
set_tris_b(0x01); // Configura RB0 como entrada, RB1-RB7 como salida
while(true){
int numero = 456;
int unidad = numero % 10;
int decena = (numero / 10) % 10;
int centena = numero / 100;
// unidad
output_a(U);
output_b(mostrar(unidad));
delay_ms(10);
output_a(0);
output_a(D);
output_b(mostrar(decena));
delay_ms(10);
output_a(0);
output_a(C);
output_b(mostrar(centena));
delay_ms(10);
output_a(0);
}
}
I hope to be able to show the number 456 well on the respective displays and then give it different uses.
Solved.
Declare
numerolikeint16,unidad,decena¢enalikeintout from main in beginning!