发表于《USB推力计套件》
novakon作者
13年5个月前修改于 12年2个月前IP:未同步
547647
1楼
源汁源味
//pfm.c
#include <stmduino.h>
uchar per=0;
void datacame(){
  pinHigh(C3);
  pinmode(A1,INPUTFL);
  
  uchar dbuf[24];
  for(uchar i=0;i<24;i++)
  {
    //send clock
    pinhigh(A2);
    pinlow(A2);
    
    //read out
    dbuf=pinread(A1);
  }
  
  for(uchar k=0;k<3;k++)
  {
    //send code for next transfer
    pinhigh(A2);
    pinlow(A2);
  }
  pinmode(A1,INPUTWAITING);
  if(per==0){
    uchar buf[3]={0,0,0};
    for(uchar b=0;b<3;b++)//24bit -> 3byte
    {
      
      for(uchar i=0;i<8;i++)
      {
        if(dbuf[b*8+i])//if this bit is 1
        {
          //set this bit of this buffer byte to 1
          buf|=1<<(7-i);
        }
      }
    }
    //most significant 16bit to int
    int value;
    *(((uchar*)&value)+0)=buf[0];
    *(((uchar*)&value)+1)=buf[1];
    
    printf("%d",value);
    endl();
  }
  pinlow(C3);
}

void main()
{
  clock(16M);
  cpudivider(1);
  
  //connect D0 to A1
  //connect CK to A2
  pinmode(A1,INPUTWAITING);//data
  pinmode(A2,OUTPUT);//clock
  
  pinmode(C3,OUTPUT);//status pin
  
  attach(datacame,A);
  waitfor(A,FALL);
  
  serial(115200);
  interrupts();
  while(1){
    sleep();
    //save power
  }
}
评论
2
文号 / 547647

万流景仰
名片发私信
学术分 16
总主题 1270 帖总回复 8407 楼拥有证书:学者 机友 笔友
注册于 2008/03/29 15:34:00最后登录 2022/01/09 14:09:34
主体类型:个人
所属领域:无
认证方式:手机号
IP归属地:0

个人简介

已走,勿送

笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的