加入星计划,您可以享受以下权益:

  • 创作内容快速变现
  • 行业影响力扩散
  • 作品版权保护
  • 300W+ 专业用户
  • 1.5W+ 优质创作者
  • 5000+ 长期合作伙伴
立即加入

基于STM32的简易电子秤仿真设计( proteus仿真+程序)

08/06 09:17
635
服务支持:
技术交流群

完成交易后在“购买成功”页面扫码入群,即可与技术大咖们分享疑惑和经验、收获成长和认同、领取优惠和红包等。

虚拟商品不可退

当前内容为数字版权作品,购买后不支持退换且无法转移使用。

加入交流群
扫码加入
获取工程师必备礼包
参与热点资讯讨论
放大
实物图
相关方案
  • 方案介绍
  • 相关文件
  • 推荐器件
  • 相关推荐
  • 电子产业图谱
申请入驻 产业图谱

仿真图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模型 风险等级 参考价格 更多信息
MKL02Z32CAF4R 1 Freescale Semiconductor Kinetis L 32-bit MCU, ARM Cortex-M0+ core, 32KB Flash, 48MHz, WL-CSP 20

ECAD模型

下载ECAD模型
$2.7 查看
ATXMEGA256A3BU-AU 1 Microchip Technology Inc IC MCU 8BIT 256KB FLASH 64TQFP

ECAD模型

下载ECAD模型
$8.44 查看
MCF52258CAG66 1 Freescale Semiconductor MCF522XX 32-bit MCU, ColdFire V2 core, 512KB Flash, 66MHz, QFP 144
$12.68 查看

相关推荐

电子产业图谱