Python基础入门例程46-NP46 菜品的价格(条件语句)

本文介绍了Python基础入门例程,通过一个实际场景——计算菜品价格,来讲解如何运用if-elif-else条件语句。用户输入菜品名称,程序根据预设价格返回菜品的费用。
摘要由CSDN通过智能技术生成
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是一个使用C51单片机的例程,用于操作HT93LC46-A串行EEPROM芯片: ```c #include <reg51.h> #include <stdio.h> sbit SDA = P1^0; // 串行数据线 sbit SCL = P1^1; // 串行时钟线 void delay_us(unsigned int us) { while (us--) { // 延时函数,延时1微秒 } } void start_condition() { SDA = 1; delay_us(2); SCL = 1; delay_us(2); SDA = 0; delay_us(2); SCL = 0; delay_us(2); } void stop_condition() { SDA = 0; delay_us(2); SCL = 1; delay_us(2); SDA = 1; delay_us(2); } void write_byte(unsigned char byte) { unsigned char i; for (i = 0; i < 8; i++) { SDA = (byte >> (7 - i)) & 0x01; // 从高位到低位依次写入数据 delay_us(2); SCL = 1; delay_us(2); SCL = 0; delay_us(2); } // 等待ACK信号 SDA = 1; delay_us(2); SCL = 1; while (SDA == 1) { // 等待ACK信号变为低电平 } delay_us(2); SCL = 0; delay_us(2); } unsigned char read_byte() { unsigned char i, byte = 0; SDA = 1; delay_us(2); for (i = 0; i < 8; i++) { SCL = 1; delay_us(2); byte = (byte << 1) | SDA; // 从高位到低位依次读取数据 SCL = 0; delay_us(2); } return byte; } void write_data(unsigned char addr, unsigned char data) { start_condition(); write_byte(0xA0); // 写入器件地址 write_byte(addr); // 写入存储地址 write_byte(data); // 写入数据 stop_condition(); } unsigned char read_data(unsigned char addr) { unsigned char data; start_condition(); write_byte(0xA0); // 写入器件地址 write_byte(addr); // 写入存储地址 start_condition(); write_byte(0xA1); // 写入器件地址(读取模式) data = read_byte(); // 读取数据 stop_condition(); return data; } void main() { unsigned char addr, data; addr = 0x00; // 存储地址 data = 0x55; // 要写入的数据 write_data(addr, data); // 写入数据到指定地址 data = read_data(addr); // 从指定地址读取数据 while (1) { // 循环执行其他操作 } } ``` 上面的例程使用了P1口的0号引脚作为串行数据线(SDA),1号引脚作为串行时钟线(SCL)。通过start_condition、stop_condition、write_byte和read_byte等函数来实现对HT93LC46-A芯片的读写操作。在主函数中,可以根据需要设置要写入的地址和数据,并通过write_data函数写入数据,然后通过read_data函数从指定地址读取数据。 请注意,以上例程只是一个简单的示例,具体的使用方法和引脚配置可能需要根据实际情况进行调整。建议参考HT93LC46-A芯片的数据手册来了解更多详细信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

heda3

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值