Home > other >  (PIC) using the buttons to complete each time you press the RD0 keys, digital tube numerical increas
(PIC) using the buttons to complete each time you press the RD0 keys, digital tube numerical increas

Time:09-17

//# include "PIC. H" contains MCU internal resources predefined
__CONFIG (HS & amp; WDTDIS & amp; LVPDIS);
The int Data;
Void delay10ms ();//delay function declaration
Void DisplayData (unsigned int Data);//display function declaration
Void init ();//IO port initialization function declaration
Void scan ();//keypad scanning program statement
B11000000 const char TableNumber []={0, 0 b11111001, 0 b10100100,
B10010010 b10110000 0, 0 b10011001, 0, 0 b10000010,
B10010000 b11111000 0, 0 b10000000, 0};
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Name: the main ()
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Int main (void)
{
Data=https://bbs.csdn.net/topics/0x00;//start time shows
init();//initialization function called
While (1)
{
Scan ();//call the scan button program
Void DisplayData (unsigned int Data);//display function declaration
}
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Name: delay10ms ()
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void delay10ms (int m)
{
Int I=0, j=0;
for(i=0; IFor (j=0; j<67; J++)
{; }
}


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Name: DisplayData ()
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void DisplayData (unsigned int Data)
{


Char I=0, j=0, k=0, x=0, Number [5]=,0,0,0,0 {0};//the Number [0] did not use the

The Number [1]=Data/1000% 10;//one thousand
The Number [2]=Data/100% 10;//one hundred
The Number [3]=Data/10% 10;//10
The Number [4]=Data/1% 10;//bits
For (x=0; x<15. I++)
{
PORTC=k=0 x01;//don't forget to each cycle it an initial value k
for(j=1; j<=4; J++)//we need to refresh the four digital tube position
{
PORTC=k;//set to light the location of the
PORTB=TableNumber [Number [j]];//set the font
Delay10ms (2);//delay shows glyph, causing the phenomenon of persistence of vision
K=k<1;//left to prepare for display the next position
}
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Name: void scan ()
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void scan ()
{


While (1)
{
If (RD0==0)//detect RD0 change
{
Delay10ms (40);//in the ISIS button to raise process longer,
//if the actual hardware, delay can be 10 milliseconds,
If (RD0==0)//that means SW really press
{
Data++;//variable Data from the gal.
}
}
}

}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Name: void init ()
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void init ()
{
TRISB=0 x00;
TRISC=0 x00;
TRISD0=1;
}

CodePudding user response:

Double-click will point position error, seems you comment that a row of * * * * *
  • Related