加入星計劃,您可以享受以下權益:

  • 創(chuàng)作內容快速變現
  • 行業(yè)影響力擴散
  • 作品版權保護
  • 300W+ 專業(yè)用戶
  • 1.5W+ 優(yōu)質創(chuàng)作者
  • 5000+ 長期合作伙伴
立即加入

基于STM32的簡易電子秤仿真設計( proteus仿真+程序)

08/06 09:17
948
服務支持:
技術交流群

完成交易后在“購買成功”頁面掃碼入群,即可與技術大咖們分享疑惑和經驗、收獲成長和認同、領取優(yōu)惠和紅包等。

虛擬商品不可退

當前內容為數字版權作品,購買后不支持退換且無法轉移使用。

加入交流群
掃碼加入
獲取工程師必備禮包
參與熱點資訊討論
放大
實物圖
相關方案
  • 方案介紹
  • 相關文件
  • 推薦器件
  • 相關推薦
  • 電子產業(yè)圖譜
申請入駐 產業(yè)圖譜

仿真圖proteus 8.9

程序編譯器:keil 5

編程語言:C語言

設計編號:C0055

主要功能:

基于STM32的簡易電子秤仿真,讀取壓力傳感器數值,帶總價自動計算,使用LCD1602顯示。

注意:矩陣鍵盤不起作用,因為沒有時間編程,其它功能正常。

Proteus仿真

img

程序

img

main函數:

主要顯示當前的壓力傳感器數值。

#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "lcd1602.h"
#include "adc0804.h"

int main(void)
{
		u8 adcx = 0;
		u8 totalll = 0;	
		uint8_t adcxxx[4] = {0, 0, 0, 0};
		uint8_t total[5] = {0, 0, 0, 0, 0};		
		LCD_init();
		ADC_init();	
		lcd_delay_ms(1000);
		LCD_write_string(0,1," WGT*PRICE=TOTAL");		
		LCD_write_string(6, 0, "*");
		LCD_write_string(10, 0, "=");
		while(1)
		{
				adcx = read_adc0804();	
				adcxxx[0] = (adcx % 100 / 10) + 0x30;
				adcxxx[1] = 46;
				adcxxx[2] = (adcx % 10) + 0x30;
				adcxxx[3] = (((adcx % 100 / 10) * (adcx % 10)) + (adcx % 10)) % 10 + 0x30;	
				totalll = ((adcx % 100 / 10) * 10 + (adcx % 10)) * 2;
				total[0] = (totalll / 100) + 0x30;
				total[1] = (totalll % 100 / 10) + 0x30;
				total[2] = 46;
				total[3] = (totalll % 10) + 0x30;
				LCD_write_string(0, 0, (char*)adcxxx);
				LCD_write_string(11, 0, (char*)total);	
				LCD_write_string(8, 0, "2");	
				lcd_delay_ms(1000);			
		}
}



LCD1602顯示驅動

#include "lcd1602.h"
#include "delay.h"
                             
#define DELAY_2N     0

void lcd_delay_us(unsigned int t)
{
	unsigned int i, j;
	
	for(i = 10; i > 0; i--)
		for(j = t; j > 0; j--);
}

void lcd_delay_ms(unsigned int t)
{	
	unsigned int i;
	
	for(i = t; i > 0; i--)
		lcd_delay_us(10);
}

//==================================================
void LCD_init(void)
{
    /*********************液晶使用的I/O口初始化**************************/ 
		GPIO_InitTypeDef GPIO_InitStructure;
	
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
  
    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_1 | GPIO_Pin_2| GPIO_Pin_0| GPIO_Pin_3
																	| GPIO_Pin_4| GPIO_Pin_5| GPIO_Pin_6| GPIO_Pin_7
																	| GPIO_Pin_8| GPIO_Pin_9| GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
	
    LCD_RW(0);			//讀寫位直接低電平,只寫不讀

    /*********************液晶初始化**************************/        
    lcd_delay_us(340); 
		LCD_RS(0);
   
    LCD_write_cmd(0x38);          // 8bit顯示模式,2行,5x7字體
    lcd_delay_ms(4);  
    LCD_write_cmd(0x08);         // 顯示關閉 
    lcd_delay_ms(4); 
    LCD_write_cmd(0x01);         // 顯示清屏 
    lcd_delay_ms(4); 
    LCD_write_cmd(0x06);         // 顯示光標移動設置 
    lcd_delay_ms(4);
    LCD_write_cmd(0x0c);         // 顯示開,光標開,光標閃爍
    lcd_delay_ms(4);
		LCD_write_cmd(0x01);         //清屏
		lcd_delay_ms(4);
}
/*--------------------------------------------------
函數說明:寫命令到液晶


---------------------------------------------------*/
void LCD_write_cmd(unsigned char cmd)
{
    LCD_RS(0);
    LCD_Write_byte(cmd);
    lcd_delay_us(340);
}
/*--------------------------------------------------
函數說明:寫數據到液晶


---------------------------------------------------*/
void LCD_write_data(unsigned char w_data)
{
    LCD_RS(1);
    LCD_Write_byte(w_data);
    lcd_delay_us(340);
}
/*--------------------------------------------------
函數說明:寫4bit到液晶
--------------------------------------------------*/
void LCD_Write_byte(unsigned char num)
{  
		if (num&0x01)
				data0(1);
		else
				data0(0);

		if (num&0x02)
				data1(1);
		else
				data1(0);

		if (num&0x04)
				data2(1);
		else
				data2(0);

		if (num&0x08)
				data3(1);
		else
				data3(0);

		if (num&0x10)
				data4(1);
		else
				data4(0);

		if (num&0x20)
				data5(1);
		else
				data5(0);

		if (num&0x40)
				data6(1);
		else
				data6(0);
		
		if (num&0x80)
				data7(1);
		else
				data7(0);
		lcd_delay_us(340);
    LCD_EN(1);
    lcd_delay_us(340);
    LCD_EN(0); 
    lcd_delay_us(340);
}

/*----------------------------------------------------
LCD_set_xy        : 設置LCD顯示的起始位置
輸入參數:x、y    : 顯示字符串的位置,X:0-15,Y:0-1                
-----------------------------------------------------*/
void LCD_set_xy( unsigned char x, unsigned char y )
{
    unsigned char address = 0;
    if (y==0) 
    {
        address=0x80+x;
    }
    else 
    {
        address=0xc0+x;
    }
//		y ? (address=0xc0+x): (address=0x80+x) ;
    LCD_write_cmd(address);
}
/*---------------------------------------------------
LCD_write_string  : 英文字符串顯示函數
輸入參數:*s      :英文字符串指針;
          X、Y    : 顯示字符串的位置                
---------------------------------------------------*/
void LCD_write_string(unsigned char X,unsigned char Y, char *s)
{
    LCD_set_xy(X,Y);   
    while (*s) 
    {
        LCD_write_data(*s);
        s++;
    }
}

//=======================================================
void LCD_wstring(unsigned char X,unsigned char *s)
{
    LCD_write_cmd(X);   
    while (*s) 
    {
        LCD_write_data(*s);
        s++;
    }
}


資料設計

下載

image-20220824012413186

  • 設計資料獲取聯系方式.doc

推薦器件

更多器件
器件型號 數量 器件廠商 器件描述 數據手冊 ECAD模型 風險等級 參考價格 更多信息
ATXMEGA192D3-MH 1 Atmel Corporation RISC Microcontroller, 16-Bit, FLASH, AVR RISC CPU, 32MHz, CMOS, 9 X 9 MM, 1 MM HEIGHT, 0.50 MM PITCH, GREEN, MO-220VMMD, MLF-64
$5.62 查看
LPC4357FET256,551 1 NXP Semiconductors LPC4357FET256 - Dual-core Cortex-M4/M0, 1 MB Flash, 136 kB SRAM, 2 HS USB with on-chip PHY, Ethernet, LCD, CAN, AES, SPIFI, SGPIO, SCT BGA 256-Pin

ECAD模型

下載ECAD模型
$15.87 查看
MK70FN1M0VMJ12R 1 Freescale Semiconductor 32-BIT, FLASH, 120MHz, RISC MICROCONTROLLER, PBGA256, 17 X 17 MM, MAPBGA-256
暫無數據 查看

相關推薦

電子產業(yè)圖譜