目录
单片机介绍
单片机又称单片微控制器,它不是完成某一个逻辑功能的芯片,而是把一个计算机系统集成到一个芯片上。概括的讲:一块芯片就成了一台计算机。它的体积小、质量轻、价格便宜、为学习、应用和开发提供了便利条件。同时,学习使用单片机了解计算机原理与结构的最佳选择。
代码列示
main.c
#include "regx52.h"
#include "LCD1602.h"
#include "stdio.h"
#include "delay.h"
#include "xpt2046.h"
sbit LED1 = P2^0;
unsigned int light_value = 0;
void main()
{
lcd1602_init();
while(1)
{
char buf[5] = {0};
light_value = xpt2046_read_adc_value(0xA4);
sprintf(buf,"%4d",light_value);
lcd1602_show_string(1,0,buf);
Delay1_ms(200);
if(light_value < 300)
LED1 = 0;
else
LED1 = 1;
}
}
LCD1602.C
#include "LCD1602.h"
#include "regx52.h"
#include "delay.h"
void lcd1602_write_cmd(unsigned char cmd)
{
LCD1602_RS = 0;
LCD1602_RW = 0;
LCD1602_EN = 0;
LCD1602_DATAPORT = cmd;
LCD1602_EN = 1;
Delay1_ms(1);
LCD1602_EN = 0;
Delay1_ms(1);
}
void lcd1602_write_data(unsigned char dat)
{
LCD1602_RS = 1;
LCD1602_RW = 0;
LCD1602_EN = 0;
LCD1602_DATAPORT = dat;
LCD1602_EN = 1;
Delay1_ms(1);
LCD1602_EN = 0;
Delay1_ms(1);
}
void lcd1602_init()
{
lcd1602_write_cmd (0x38);
lcd1602_write_cmd (0x0c);
lcd1602_write_cmd (0x06);
lcd1602_write_cmd (0x01);
}
void lcd1602_show_string(unsigned char x,unsigned char y,unsigned char *str)
{
if (y == 0)
lcd1602_write_cmd(0x80 + 0x00 + x);
if (y == 1)
lcd1602_write_cmd(0x80 + 0x40 + x);
while (*str != '\0')
{
lcd1602_write_data(*str);
str++;
}
}
main.c
#include "regx52.h"
#include "LCD1602.h"
#include "stdio.h"
#include "delay.h"
#include "xpt2046.h"sbit LED1 = P2^0;
unsigned int light_value = 0;
void main()
{
lcd1602_init();
while(1)
{
char buf[5] = {0};
light_value = xpt2046_read_adc_value(0xA4);
sprintf(buf,"%4d",light_value);
lcd1602_show_string(1,0,buf);
Delay1_ms(200);
if(light_value < 300)
LED1 = 0;
else
LED1 = 1;
}
}
LCD1602.C
#include "LCD1602.h"
#include "regx52.h"
#include "delay.h"void lcd1602_write_cmd(unsigned char cmd)
{
LCD1602_RS = 0;
LCD1602_RW = 0;
LCD1602_EN = 0;
LCD1602_DATAPORT = cmd;
LCD1602_EN = 1;
Delay1_ms(1);
LCD1602_EN = 0;
Delay1_ms(1);
}void lcd1602_write_data(unsigned char dat)
{
LCD1602_RS = 1;
LCD1602_RW = 0;
LCD1602_EN = 0;
LCD1602_DATAPORT = dat;
LCD1602_EN = 1;
Delay1_ms(1);
LCD1602_EN = 0;
Delay1_ms(1);
}void lcd1602_init()
{
lcd1602_write_cmd (0x38);
lcd1602_write_cmd (0x0c);
lcd1602_write_cmd (0x06);
lcd1602_write_cmd (0x01);
}
void lcd1602_show_string(unsigned char x,unsigned char y,unsigned char *str)
{
if (y == 0)
lcd1602_write_cmd(0x80 + 0x00 + x);
if (y == 1)
lcd1602_write_cmd(0x80 + 0x40 + x);
while (*str != '\0')
{
lcd1602_write_data(*str);
str++;
}
}
代码解释
光敏电阻在现实中有重要的地位 可以采光
系统运用了51单片机作为主控制器
对系统的工作流程介绍如下;
上电后 用手可以检测到光的强弱
学习心得
首先,我想简单回顾一下我参与的这门学习课程。这门课程是一门深入的学科课程,涵盖了广泛的主题,包括理论学习、实践操作和互动讨论。我作为学员,通过这门课程,不仅增强了对学科知识的理解,还提高了自我探究和解决问题的能力。
我参与这门课程的过程大致是这样的:首先,老师详细介绍了各个知识点,我们则通过课堂讨论和作业来加深对这些知识的理解。在老师的引导下,我们进行了一系列的讨论和演讲,以进一步强化我们的理解。这样的学习过程让我更加深入地理解了课程内容,同时也锻炼了我的思考和表达能力。谢谢大家的支持