找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1940|回复: 0
打印 上一主题 下一主题
收起左侧

新手来的,谁能帮我改下,我用ICC编译有错但是不知怎么修改。

[复制链接]
跳转到指定楼层
楼主
ID:86731 发表于 2015-7-24 16:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include <iom8v.h>
#include <macros.h>
#include <stdlib.h>
#include <lcd.h>
#include <math.h>
#include<string.h>
#define S0   1<<0    //pc0 gnd
#define S1   1<<1    //2v
#define S2   1<<7    //200mv   PD7
#define S3   1<<2    //-vref
#define S4   1<<4    //-20mv
#define S5   1<<3    //discharge
#define S6   1<<5    //Ux
#define S7   1<<6    //Ix
   
//全局变量
unsigned char timetemp=0;
unsigned char time100ms=0;
unsigned int time500ms=0;
unsigned char stepflag=0;//转换阶段标志 -uref ? -uref/2 7?
unsigned char conflag=0; //正在转换标志
unsigned int  voltcount=0;  //ad值
float         volt=0;       //电压值
unsigned char timeH=0;     //计数器值
unsigned char timeL=0;
//函数
void init_devices(void);
void port_init(void);
//1ms
void timer2_init(void);
void timer2_ovf_isr(void);
//100us
void timer1_init(void);
void timer1_ovf_isr(void);
void adadjust(void);
void adini(void);
void adconvert(unsigned char data);
//main()
void main()
{
unsigned char i;
unsigned char lcdbuf[32];
unsigned char *lcdp=lcdbuf;
init_devices();
Inti_Disp();
adadjust();
adini();
  
while(1)
  {
   adini();
   adconvert(0x08);//
   set_cur(0);
   lcdp=ftoa(volt,0);   
   putstr(lcdp);
   set_cur(16);
   ltoa(lcdbuf,voltcount,10);
   putstr(lcdbuf);
   
  }
  
//abc();
}
void adini(void)
{
  
    PORDC=0x08; //放电30ms
    timetemp=30;
    conflag=1;   
  
   
}
void adconvert(unsigned char data)//充电
{
       //充电196ms   
       PORDC=data; //打开Ux
       timetemp=196;
       conflag=1;   
       while(timetemp);//等待
       //反向放电
          //读取U0值         
          if(PIND&0x08)
            {
              PORDC=0x10;//接入-uref/2 7
              stepflag=1;//qi dong counter
              timeH=0;
              timeL=0;
            
            }
          else
           {
            PORDC=0x04;//接入-uref
            stepflag=2; //qi dong counter
            timeH=0;
                timeL=0;
           }
dischar1:  
          while(stepflag==2)
            {
             if(PIND&0x08)
                {
                 
                }
              else
                {
                 PORDC=0x10;//接入-uref/2 7
                    stepflag=1;//qi dong counter
                }  
            
              }
          while(PIND&0x04);
          voltcount=timeH;
          voltcount=(voltcout<<7)+timeL;
            
}
void port_init(void)
{
PORTB = 0xFF;
DDRB  = 0xff;
PORTC = 0x08; //m103 output only
DDRC  = 0xff;
PORTD = 0x7F;
DDRD  = 0xf3;
}
//TIMER1 initialisation - prescale:64
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 500uSec
// actual value: 500.000uSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFF; //setup
TCNT1L = 0x83;
OCR1AH = 0x00;
OCR1AL = 0x7D;
OCR1BH = 0x00;
OCR1BL = 0x7D;
ICR1H  = 0x00;
ICR1L  = 0x7D;
TCCR1A = 0x00;
TCCR1B = 0x03; //start Timer
}
#pragma interrupt_handler timer1_ovf_isr:9
void timer1_ovf_isr(void)
{
//TIMER1 has overflowed
TCNT1H = 0xFF; //reload counter high value
TCNT1L = 0x83; //reload counter low value
if(stepflag==1)
    {
     //timeH
     timeL++;
     
    }
if(stepflag==2)
   {
     timeH++;
   }
}
//TIMER2 initialisation - prescale:64
// WGM: Normal
// desired value: 1mSec
// actual value:  1.000mSec (0.0%)
void timer2_init(void)
{
TCCR2 = 0x00; //stop
ASSR  = 0x00; //set async mode
TCNT2 = 0x06; //setup
OCR2  = 0xFA;
TCCR2 = 0x04; //start
}
//1ms
#pragma interrupt_handler timer2_ovf_isr:5
void timer2_ovf_isr(void)
{
TCNT2 = 0x06; //reload counter value
if(timetemp!=0)
   timetemp--;
else
   conflag=0;  
   
if(time500ms==0)
   {
     PORTC^=0x20;  
     time500ms=500;
   }
time500ms--;
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
  timer1_init();
timer2_init();
MCUCR = 0x00;
GICR  = 0x00;
TIMSK = 0x44; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表