功能:
控制電機(jī)加速、減速、反向、指示燈顯示功能。
#include "key.h"
#include "delay.h"
#include "main.h"
// extern unsigned char key_flag=0;
extern unsigned char key_flag;
extern unsigned char key_value;
//外部中斷初始化
void Int0_Init (void){
EA=1;
IT0=1; //下降沿觸發(fā)
}
//外部中斷函數(shù)
void int0() interrupt 0{
key_flag=1;
// IE=0x80; //屏蔽中斷
P1=0xff;
key_value=P1;
// IE=0x81; //開(kāi)啟中斷
}
#include "delay.h"
void Delay_ms(unsigned int n)
{
unsigned int i,j;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
nclude "key.h"
#include "delay.h"
#include "motor.h"
// #include "picture.h"
//定義
unsigned char key_flag;
unsigned char key_value;
unsigned char duty=5;
unsigned char t;
void main(){
// EA=1;
// IE=0x81; // 允許INT0中斷
// IT0=1; //下降沿觸發(fā)
key_flag=0;
Time0_Init(); //初始化定時(shí)器0
Time1_Init(); //初始化計(jì)數(shù)器1
Int0_Init(); //初始化外部中斷
OLED_Init(); //初始化OLED
OLED_Clear(); //清屏
while(1){
// OLED_ShowString(0,0,"rpm:",14);
// //
// OLED_ShowNum(40,5,t,3,14);
//
OLED_ShowString(64,0,"duty: 0%",14);
//
OLED_ShowNum(104,0,duty,1,14);
//
//按鍵判斷
if (key_flag==1){
switch (key_value){
case 0xfe: speed_up(); //加速11111110
break;
case 0xfd: speed_cut(); //減速11111101
break;
資料借鑒于此?紛傳
閱讀全文