⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 err_debug_main.c

📁 平缝机的单片机伺服控制系统源代码。本程序为用单片机控制永磁同步电机的低成本方案
💻 C
字号:
//ICC-AVR application builder : 2005-7-14 20:07:57
// Target : M88
// Crystal: 8.0000Mhz

#include <iom88v.h>
#include <macros.h>
#include "Err.h"

void  timer1_ovf_isr_(void);

//宏定义:定义常用口线操作等,具体应用前应根据实际情况修改!
//#define LEDFLICKTIME1		 	  50			//  LED 灯闪烁时亮的时间T1 * 10 ms
//#define LEDFLICKTIME2			  50		    //  LED 灯闪烁时灭的时间T2 * 10 ms
//#define LEDFLICKTIME3			  150			//  LED 灯闪烁时两次闪烁间隔时间T3 * 10 ms

byte g_ErrCode01,g_ErrCode02;	//  故障代码 每一位指代不同的故障//  初始化为0
word g_Over220VCnt;					// 记录超过220v 的次数//  初始化为0
word g_Lower220VCnt;					// 记录低于220v 的次数//  初始化为0
word g_Over400VCnt;					// 记录超过400v 的次数//  初始化为0
word g_Lower400VCnt;					// 记录低于400v 的次数//  初始化为0
word g_LowSpeedCnt;					// 记录电机速度小于10 RPM 的次数//  初始化为0
byte g_LedTimesCnt;					// LED 灯闪烁次数计数//  初始化为0
byte g_LedTimes;					//  LED 灯闪烁次数 //  初始化为0
byte g_LedTimesT1;					// LED 灯闪烁时亮的时间统计 10ms 为单位//  初始化为0
byte g_LedTimesT2;					//LED 灯闪烁时灭的时间统计 10ms 为单位//  初始化为0
word g_LedTimesT3;					//LED 灯闪烁时间隔的时间统计 10ms 为单位//  初始化为0

byte g_MotorRun;					// 电机运动状态标志 :  1 表示运行 0 表示停止//  初始化为0
byte g_LowVol;					// 确定检测到欠压标志:  1 表示欠压//  初始化为0
byte g_singleLowVol;					// 单次欠压标志:  1 表示欠压//  初始化为0
byte g_SynEncoderErr;					// 同步编码器故障:  1 表示发生故障//  初始化为0
byte g_MotorBlock;					//电机堵转标志:  1 表示发生电机堵转//  初始化为0
byte g_LowSpeed;					// 电机速度小于10 RPM 标志1 表示速度小于10 RPM //  初始化为0
byte g_NostopNeedle;			// 无停针信号标志 : 1 表示无停针信号//  初始化为0
byte g_OverVol;					// 确定检测到过压标志:  1 表示过压//  初始化为0
byte g_SingleOverVol;					// 单次过压标志:  1 表示过压//  初始化为0
byte g_HallErr;					// 电机HALL信号故障 标志1 表示电机HALL信号故障  //  初始化为0
byte g_LedType;					// LED 灯闪烁类别  1 红灯  0  绿灯 //  初始化为0
byte g_StartLedFlick;				// 启动LED 灯闪烁标志//  初始化为0
byte g_LedTimes;					//  LED 灯闪烁次数   1 表示 开始闪烁  //  初始化为0
byte g_E_Mag_No;					//  选择电磁铁的序号1~3	//  初始化为1
byte g_Err_Det_Disable;					//  故障检测禁止1 表示禁止检测故障 //  初始化为0


void port_init(void)
{
 PORTB = 0x00;
 DDRB  = 0x00;
 PORTC = 0x00; //m103 output only
 DDRC  = 0x00;
 PORTD = 0x00;
 DDRD  = 0x00;
}

//TIMER0 initialize - prescale:1024
// WGM: Normal
// desired value: 10mSec
// actual value:  9.984mSec (0.2%)
void timer0_init(void)
{
 TCCR0B = 0x00; //stop
 TCNT0 = 0xB2; //set count
 TCCR0A = 0x00; 
 TCCR0B = 0x05; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:17
void timer0_ovf_isr(void)
{
 //TIMER0 has overflowed
 TCNT0 = 0xB2; //set count
 
 timer1_ovf_isr_();
 
 
 
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 timer0_init();

 MCUCR = 0x00;
 EICRA = 0x00; //extended ext ints
 EIMSK = 0x00;
 
 TIMSK0 = 0x01; //timer 0 interrupt sources
 TIMSK1 = 0x00; //timer 1 interrupt sources
 TIMSK2 = 0x00; //timer 2 interrupt sources
 
 PCMSK0 = 0x00; //pin change mask 0 
 PCMSK1 = 0x00; //pin change mask 1 
 PCMSK2 = 0x00; //pin change mask 2
 PCICR = 0x00; //pin change enable 
 PRR = 0x00; //power controller
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

//
void main(void)
{
 byte i;
 
 i  = 1;
 init_devices();
 //insert your functional code here...
 	while (1)
	{
		//det_err();
		if (i)

		led_flicker(1,3);
		
		i = 0;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -