#include "io430.h"
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
P1SEL &=~ BIT2;
P1DIR &=~ BIT2;//SDA
P2DIR |= BIT2;//SCK
P2DIR |=BIT2;
P2SEL |=BIT2;
P2OUT |=BIT2;
//get_pizhong();
// LCD_init(); //初始化液晶
// LCD_clear();
//int a=8;
//j= sprintf( buffer,"%d",a);
// LCD_write_english_string(0,0,buffer);
while(1)
{
get_weight();//得到重量
// j= sprintf( buffer,"%d",weight);
// LCD_write_english_string(0,0,buffer);
}
return 0;}
#include <msp430f5529.h>
#include <HX711.h>
#include <stdio.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
unsigned long count;
int j;
int weight=0;
char buffer[200];
double money;
uint temp;
ulong a;
uint aa;
ulong hx711_dat;
uint get;
//延時函數
void delayus(uint t)
{
//_nop_();
//_nop_();
while(t--);
}
// I/O配置
//讀取HX711
unsigned long ReadCount(void) //增益128
{
unsigned long count;
unsigned char i;
P1IN |= BIT2; //SDA
delayus(4);
P2OUT &= ~BIT2;//SCK
count=0;
while( P1IN&BIT2 ); //SDA
for(i=0;i<24;i++)
{
P2OUT |= BIT2; //SCK
count=count<<1;
P2OUT &=~ BIT2;//SCK
if(P1IN&BIT2)//SDA
count++;
}
P2OUT |= BIT2; //SCK
delayus(4);
count=count^0x800000;
P2OUT &=~ BIT2;//SCK
return(count);
}
void get_pizhong() //獲取皮重,秤盤重量
{
uint j;
// ulong hx711_dat;
for(j=0;j<5;j++)
delayus(4);
hx711_dat=ReadCount(); //HX711AD轉換數據處理
temp=(uint)(hx711_dat/100); //縮放long數據為int型,方便處理
}
void get_weight() //獲取被測物體重量
{
ulong hx711_data;
uint j;
char buffer[200];
hx711_data=ReadCount(); //HX711AD轉換數據處理
UART0_Sendint(weight);
get=(uint)(hx711_data/100);
if(get<(temp+4)) //判斷是否有正向重量
{
while(get<(temp+56362))
{
weight=0;
weight_shuzhi(weight);//顯示重量
j= sprintf( buffer,"%d",weight);
LCD_write_english_string(0,0,buffer);//顯示重量
hx711_data=ReadCount(); //HX711AD輸出數據處理
get=(uint)(hx711_data/100);
if(get>(temp+1))break;
}
}
a=ReadCount();
aa=(uint)(a/100)-temp;
weight=(uint)((float)aa/100);//重量轉換函數,傳感器型號不同此函數要適當修改
}
/*
#pragma vector = TIMERB0_VECTOR
__interrupt void TIMERB0_ISR(void)
{
}
*/
|