标题: iccAVR编程+proteus仿真问题求解 [打印本页]

作者: 辣椒是地方    时间: 2015-6-23 17:23
标题: iccAVR编程+proteus仿真问题求解
程序加到电路中仿真始终没法让K6控制Q1的通断,请求大神赐教。。。。程序哪里有不对的地方,多学习了。。。
电路图如下所示
程序如下所示

#define F_CPU 12000000UL
#include <iom16v.h>
#define uchar    unsigned char
#define uint     unsigned int
#include "macros.h"
#include <eeprom.h>
#include <math.h>
//--------------------------------
//主程序
//-------------------------------------

void main(void)
{  

   DDRD|=BIT(PD4);              //PD4端口输出
   PORTD&=~BIT(PD4);            //断开继电器
   DDRB=0X00;                   //PB2端口输入
   PORTB|=0xFF;                 //PB2端口内部上拉


while(1)
  {
  if(PINB&0x04==0)
         {
          while(PINB&0x04==0);
          PORTD|=BIT(PD4);
          delay_nms(5000);
      PORTD&=~BIT(PD4);
     }
  }
}

void delay_1us(void)                 //1us延时函数
{
  asm("nop");
  }

void delay_nus(unsigned int n)       //N us延时函数
{while(n--)
   ;
  }

void delay_1ms(void)                 //1ms延时函数
  {
   unsigned int i;
   for (i=0;i<1428;i++);
  }
void delay_nms(unsigned int n)       //Nms延时函数
  {
   unsigned int i=0;
   for (i=0;i<n;i++)
   delay_1ms();
  }



QQ图片20150623171658.png (18.42 KB, 下载次数: 277)

proteus仿真电路图

proteus仿真电路图





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1