**************************************** ***************************
Name: Tang xiangheng
Copyright:
Author:
Date: 26-10-09 :52
Description:
**************************************** ****************************/
/*************************************** ****************************
Function: checks whether the 4*4 keyboard is pressed. If yes, the serial number of the two buttons is displayed in the middle.
If no buttons are displayed, the HH S5 enables the 3, 4 dial switch, and the S6 switches are all enabled.
Define the C-port for output, select XT for shock, disable the watchdog timer, and perform low-voltage reset.
Device: PIC demoii engineering board, pic18f4520 chip, pic16-mcd2
Online Debugger
**************************************** ****************************/
# Include <pic18.h>
Void delay (); // latency function declaration
Void Init (); // I/O port initialization function declaration
Void display (int x); // display function declaration
Int result;
//************************************** ***************************
Int main ()
{
Init (); // call the initial I/O port Function
Result = 0xff;
If (rb0 = 0)
{
ASM ("NOP"); // insert a certain delay to ensure level stability here to eliminate Jitter
Result = 0x01;
}
If (Rb1 = 0)
{Rbpu = 0; // enables intcon2 interrupt registers to be pulled internally on port B.
ASM ("NOP"); // insert a certain delay to ensure level Stability
Result = 0x02;
}
If (Rb2 = 0)
{
ASM ("NOP"); // insert a certain delay to ensure level stability here to eliminate Jitter
Result = 0x03;
}
If (Rb3 = 0)
{
ASM ("NOP"); // insert a certain delay to ensure level stability here to eliminate Jitter
// If (rb0 = 0) // No jitter is required. If this statement is used, the key is invalid.
//{
Result = 0x04;
//}
}
If (rb4 = 0)
{
ASM ("NOP"); // insert a certain delay to ensure level stability here to eliminate Jitter
Result = 0x05;
}
Display (result );
}
//************************************** ****************************
Void delay () // latency Function
{
Int I;
For (I = 100; I> 0; I --){;}
}
//************************************** *****************************
Void Init () // I/O port initialization Function
{
Adcon1 = 0x07; // set port A to a normal I/O port
Trisa = 0x33; // set (enable the 3rd and 4 digital tubes)
Trisd = 0x00; // outputs all the bit settings of the digital tube
Trisb = 0x1f; // set the lower 5 bits of port B to input other unused
Porta = 0xff;
Portd = 0xff; // All lights are out at the beginning
// Config3h = 0x05; // pbaden = 0; config3h is the register in the configuration bit, pbaden = 0 is to configure the RB0-RB4 as a digital I/O
Rbpu = 0; // enables intcon2 interrupt registers to be pulled internally on port B.
}
//************************************** **************************
Void display (int x) // display function: press the button to display the serial number.
{
Switch (result)
{
Case 0x01:
Porta = 0x37; // open 4th digital Tubes
Portd = 0xc0; // display 0
Delay (); // latency
Porta = 0x3b; // open 3rd digital Tubes
Portd = 0xf9; // display 1
Delay (); break;
Case 0x02:
Porta = 0x37; // open 4th digital Tubes
Portd = 0xc0; // display 0
Delay (); // latency
Porta = 0x3b; // open 3rd digital Tubes
Portd = 0xa4; // display 1
Delay (); break;
Case 0x03:
Porta = 0x37; // open 4th digital Tubes
Portd = 0xc0; // display 0
Delay (); // latency
Porta = 0x3b; // open 3rd digital Tubes
Portd = 0xb0; // display 1
Delay (); break;
Case 0x04:
Porta = 0x37; // open 4th digital Tubes
Portd = 0xc0; // display 0
Delay (); // latency
Porta = 0x3b; // open 3rd digital Tubes
Portd = 0x99; // display 1
Delay (); break;
Case 0x05:
Porta = 0x37; // open 4th digital Tubes
Portd = 0xc0; // display 0
Delay (); // latency
Porta = 0x3b; // open 3rd digital Tubes
Portd = 0x92; // display 1
Delay (); break;
Case 0xff:
Porta = 0x37; // open 4th digital Tubes
Portd = 0x89; // display 0
Delay (); // latency
Porta = 0x3b; // open 3rd digital Tubes
Portd = 0x89; // display 1
Delay (); break;
}
}