1. Function Description: press the button and the digital tube starts from 0 to 9 and is reset to 0.
2. The Code is as follows: you are welcome to optimize it as the best code.
/*
Data: 20091010
For: button drive LED
Tool: Ht ide 3000 v7.0
MCU: HT48R50A-1
Fsys: 4 MHz
ASM/C: c
VPM: Yes
*/
# Include "self-HT48R50A-1.h"
// For Segs-Com0
# Define segsport _ Pa
# Define segsctrl _ pac
# Define ptrport _ pb6
# Define ptrctrl _ pbc6
# Define com0port _ pb7
# Define com0ctrl _ pbc7
// For button
# Define swport _ pc0 // Switch Port
# Define swctrl _ pcc0 // switch controlling
// Variable
Int icntbutton;
// Function
Int getswitchstatus (void );
Void blinksegs (INT );
// The main function
Void main (void)
{
Int I;
Segsport = 0x00; // turn off segs
Segsctrl = 0x00; // output
Com0ctrl = 0;
Ptrctrl = 0;
Com0port = 0;
Ptrport = 0;
Swctrl = 1; // Input
Icntbutton = 0;
While (1)
{
_ Delay( 10000 );
Getswitchstatus ();
Blinksegs (icntbutton );
}
}
// Function ==========================================
Int getswitchstatus ()
{
Swctrl = 1;
If (0 = swport)
{
Icntbutton ++;
Icntbutton = icntbutton % 10;
While (0 = swport)
{
_ Delay( 1000 );
}
Return 0xff;
}
Return 0x00;
}
// Function -----------------------------------
Void blinksegs (INT sum)
{
Char iblink;
Char segs [10] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
Iblink = segs [Sum];
Segsport = iblink;
}
// ================================================ ========
3. Simulation browsing address:
Http://p.blog.csdn.net/images/p_blog_csdn_net/duojinian/EntryImages/20091013/Segs_Driver_20091013.jpg