Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Urgent Help! - Displaying a changing number from a register on a 7 seg display

Status
Not open for further replies.

Calbar

Newbie level 4
Joined
Nov 23, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,324
Hi All,


This is probably quite trivial, but I am currently making a simple game using MpLab and it is my first time programming.

I am trying to create a 'lives' counter, so that every time a question is answered wrong, a life is taken away and then the new life number is displayed on a 7 seg.

I am using a 16F628 PIC and hyperterminal as the interface with a Max232 in the circuit.

I have been told that I need to create a new register, which has been done, and then apparently I need to give this register a value, to which 1 is taken away everytime a wrong answer is given. Once this is done, I then want to display what is in the register, onto the 7 seg display. I want to start with 9 lives, and go down to 0.


Hope this makes sense and is possible


Cheers

Calbar
 

// Lcd pinout settings
sbit LCD_RS at Rd4_bit;
sbit LCD_EN at Rd5_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_D6 at Rd2_bit;
sbit LCD_D5 at Rd1_bit;
sbit LCD_D4 at Rd0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISd4_bit;
sbit LCD_EN_Direction at TRISd5_bit;
sbit LCD_D7_Direction at TRISd3_bit;
sbit LCD_D6_Direction at TRISd2_bit;
sbit LCD_D5_Direction at TRISd1_bit;
sbit LCD_D4_Direction at TRISd0_bit;

void main() {
unsigned int x=0;
unsigned char hundreds,tens,ones,rem;
lcd_init();
lcd_out(1,1,"TEXT:");
lcd_out(1,10,"deg c");
for(;;)
{
if(RB0_bit==0)
{
delay_ms(10);
if(RB0_bit==0)
{
x++; // variable it's value changed by clicking a button making counting
hundreds = x/100;
lcd_chr(1,7,0x30+hundreds); // divide number
rem = x%100;
tens =rem/10;
ones=tens%10;
lcd_chr(1,8,0x30+tens);
lcd_chr(1,9,0x30+ones);
if(x==999)
{
x=0;
}
for(;RB0_bit==0;)
{}
}

}
if(RB1_bit==0)
{
delay_ms(10);
if(RB1_bit==0)
{
x--;
hundreds = x/100;
lcd_chr(1,7,0x30+hundreds); //displayying it in hex
rem = x%100;
tens =rem/10;
ones=tens%10;
lcd_chr(1,8,0x30+tens);
lcd_chr(1,9,0x30+ones);
if(x==999)
{
x=0;
}
for(;RB1_bit==0;)
{}

}

}


}

}

this program reads number and then display it as i think
i programmed it a long time ago , i can't remember it's exact objective but the lines commented above is the same as you want i think except that it written in C
 
  • Like
Reactions: kabiru

    kabiru

    Points: 2
    Helpful Answer Positive Rating
Thanks for the rapid response, but i need the code so that it can be used in MpLab.

I think i need something like: 'decf REGISTER_LIVES,F' in the text to tell it to subtract from the register, and also:

movlw .9 ;.9 needs to be changed
movwf REGISTER_L


so that 9 lives are put in the literal register, then moved to the working register. Or something alone those lines
 

x--;
hundreds = x/100;
lcd_chr(1,7,0x30+hundreds); //displayying it in hex
rem = x%100;
tens =rem/10;
ones=tens%10;
lcd_chr(1,8,0x30+tens);
lcd_chr(1,9,0x30+ones);


i didn't use mplab but the idea is that i have a variable called X that incremented or decremented by two push buttons and to display it
i used function lcd_chr() it used to display a character you of course will find something like it in your compiler library in mplab
i put variable hundreds and then sum 0x30 or 30 hexadecimal number so that it can be displayed in ASCII
hope to be helpful
 
  • Like
Reactions: kabiru

    kabiru

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top