📄 paomadeng.c
字号:
//-----------------------------------------------------------------------------
// F00x_Ports_SwitchLED.c
//-----------------------------------------------------------------------------
// Copyright 2005 Silicon Laboratories, Inc.
// http://www.silabs.com
//
// Program Description:
//
// This program demonstrates how to configure port pins as digital inputs
// and outputs. The C8051F005 target board has one push-button switch
// connected to a port pin and one LED. The program constantly checks the
// status of the switch and if it is pushed, it turns on the LED.
//
//
// How To Test:
//
// 1) Download code to a 'F005 target board
// 2) Ensure that the J1 and J3 headers are shorted
// 3) Push the button (P1.7) and see that the LED turns on
//
//
// FID: 00X000002
// Target: C8051F00x
// Tool chain: Keil C51 7.50 / Keil EVAL C51
// Command Line: None
//
// Release 1.0
// -Initial Revision (GP)
// -15 NOV 2005
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <c8051f000.h> // SFR declarations
#define SYSCLK 11059200 // SYSCLK in Hz (16 MHz internal
// oscillator)
// the internal oscillator has a
// tolerance of +/- 20%
//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
sbit rd = P1^7;
sbit re = P1^5;
sbit wr = P1^6;
sbit addr0 = P1^0;
sbit addr1 = P1^1;
sbit addr2 = P1^2;
sbit addr3 = P1^3;
sbit addr4 = P1^4;
sbit data0 = P2^0;
sbit data1 = P2^1;
sbit data2 = P2^2;
sbit data3 = P2^3;
sbit lcd_en = P3^0;
unsigned int n,m,l;
void write (int addr, int datain);
unsigned int read();
void OSCILLATOR_Init (void);
void PORT_Init (void);
void delay(int time_ms);
//-----------------------------------------------------------------------------
// Initialization Subroutines
//-----------------------------------------------------------------------------
unsigned int read()
{
unsigned int data_rd;
PRT2CF &= 0xf0;
P2=0xff;
rd=0;
data_rd=P2;
data_rd &=0x0f;
rd=1;
PRT2CF |= 0xff;
return data_rd;
}
//-----------------------------------------------------------------------------
// OSCILLATOR_Init
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void OSCILLATOR_Init (void)
{
OSCICN |= 0x03; // Configure internal oscillator for
OSCXCN=0xff; // its maximum frequency (24.5 Mhz)
}
//-----------------------------------------------------------------------------
// PORT_Init
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void PORT_Init (void)
{
PRT1CF |= 0xff; // P1.6 is push-pull
PRT2CF |= 0xff; // P1.6 is push-pull
// PRT0CF |= 0xff; // P1.6 is push-pull
// PRT3CF |= 0xff; // P1.6 is push-pull
// P1.7 is open-drain
P1 |= 0xa0; // Set P1.7 latch to '1'
XBR0 = 0x00;
XBR1 = 0x00;
XBR2 = 0x40; // Enable crossbar and enable
// weak pull-ups
}
void write (int addr, int datain)
{
char pp;
PRT2CF |= 0xff;
pp=addr;
pp|= 0xA0;
P1 =pp;
P2=datain;
wr=1;
wr=0;
}
//-----------------------------------------------------------------------------
// main() Routine
//-----------------------------------------------------------------------------
void main (void)
{
unsigned int temp1,temp2,xor1,wei1,wei2,temp_wei;
int i1,i2,i3,i4;
WDTCN = 0xde; // Disable watchdog timer
WDTCN = 0xad;
OSCILLATOR_Init (); // Initialize Oscillator
PORT_Init(); // Initialize Port I/O
lcd_en=0;
for(;;)
{
write(0,14);
delay(100);
write(0,13);
delay(100);
write(0,11);
delay(100);
write(0,7);
delay(100); // end of while(1)
}
} // end of main()
//-----------------------------------------------------------------------------
// Interrupt Service Routines
//-----------------------------------------------------------------------------
void delay(int time_10ms)
{
for (n=0;n<=time_10ms;n++)
{
for(m=0;m<=10;m++)
{
for(l=0;l<=80;l++) ;
}
}
}
//-----------------------------------------------------------------------------
// End Of File
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -