 
- UID
- 373967
- 帖子
- 9428
- 主題
- 2609
- 精華
- 0
- 積分
- 1023
- 楓幣
- 49
- 威望
- 999
- 存款
- 38807
- 贊助金額
- 0
- 推廣
- 0
- GP
- 1205
- 閱讀權限
- 70
- 在線時間
- 477 小時
- 註冊時間
- 2023-1-12
- 最後登入
- 2025-3-15
|
基於PIC16F72的磅秤程式碼,可以讀取0到300公斤的重量並顯示小數點,但我們仍然無法提供具體的零件腳位配置,因為該資訊需要進一步的詳細設計和製作。請注意,此程式碼僅供參考和學習之用,實際的應用需要進一步的測試和校準。
arduino
#include <16F72.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#byte trisa=0x85
#byte porta=0x05
#byte trisb=0x86
#byte portb=0x06
#bit led1=portb.0
float weight;
int units;
int tenths;
int hundredths;
void init_serial(){
#asm
movlw 0x8
movwf TXSTA
movlw 0x90
movwf RCSTA
movlw 0x20
movwf SPBRG
#endasm
}
void main(){
trisa=0b00001000;
trisb=0;
portb=0;
setup_adc_ports(RA3_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
init_serial();
while(TRUE){
delay_ms(1000);
weight=read_adc()*0.488;
units=(int)weight;
tenths=(int)((weight-units)*10);
hundredths=(int)((((weight-units)*10)-tenths)*10);
printf("%d.%d%d kg\r\n", units, tenths, hundredths);
if(units>=300){
led1=1;
}
else{
led1=0;
}
}
} |
|