- UID
- 856476
|
点亮LED灯程序:#include <p18f45k22.h>//头文件,对单片机引脚的功能定义,必须加入正确才有效工作。
//#pragma config FOSC = INTIO67, FCMEN = OFF, IESO = OFF // CONFIG1H #pragma config FOSC = XT, FCMEN = OFF, IESO = OFF
#pragma config FOSC = HSMP, FCMEN = OFF, IESO = OFF
#pragma config PWRTEN = OFF, BOREN = SBORDIS, BORV = 285 //CONFIG2L
#pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H
#pragma config MCLRE = INTMCLR, LVP = OFF // CONFIG3H
//#pragma config STVREN = ON, LVP = OFF, XINST = OFF // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF , CP2 = OFF,CP3 = OFF // CONFIG5L
#pragma config CPB = OFF, CPD = OFF // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF,WRT2 = OFF, WRT3 = OFF // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF,EBTR3 = OFF // CONFIG7L
#pragma config EBTRB = OFF
//以上信息为配置位信息,根据你的需求配置正确才可以工作。
void main()
{
ANSELA=0×00;//控制I/O口是模拟端口还还是数字端口,ANSELAx=0,为数字端口,为1是模拟端口。 TRISA=0×00;//数据方向寄存器,为0是输出,为1是输入
LATA=0xFF;//输出控制,将输出值控制锁存器输出设定的值。还有一个PORT它是读取引脚电平的,但是在pic16系列却可以输出引脚电平,在此,希望大家可以看清手册操作。
while(1);//
}
以上就是针对led的操作,下次我将详细介绍下PIC单片机的配置位信息,并补充PORTA端口的知识。 |
|