#include
#include "../delay/delay.h"
#include "lcd.h"
/*====================================================
Determine write command/data function
=====================================================*/
void lcd_write(unsigned char byte, unsigned char flag)
{
if(flag)
{
RS = 1; //Select data register
}
else
{
RS = 0; //Select instruction register
}
RW = 0; //write
E = 1; //Select LCD
LCDPORT = byte;
delay_us(5); //stable
E = 0; //Disable LCD
}
/*====================================================
LCD initialization function
=====================================================*/
void lcd_init()
{
delay_ms(15);
lcd_write(0x38,LCD_WRITE_COM); //Display 8-bit data interface, two-line display, 5*7 dot matrix characters
delay_ms(5);
lcd_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x38,LCD_WRITE_COM);
delay_ms(5);
lcd_write(0x08,LCD_WRITE_COM); //Turn off the display and the blinking of the cursor
delay_ms(5);
lcd_write(0x01,LCD_WRITE_COM); //清屏
delay_ms(5);
lcd_write(0x06,LCD_WRITE_COM); //Set the pointer mode, the picture does not shift
delay_ms(5);
lcd_write(0x0c,LCD_WRITE_COM); //Turn on the display
delay_ms(5);
}
/*====================================================================================
Write character function
函数原型:void lcd_dis_byte(unsigned char x, unsigned char y, unsigned char byte);
Note: x is the row (1-2), y is the column (1-8).
=====================================================================================*/
void lcd_dis_byte(unsigned char x, unsigned char y, unsigned char byte)
{
unsigned char add;
if(((0 == x) || (x > 2)) || ((0 == y) || (y > 16)))
{
return ;
}
add = 0x80 + (x - 1) * 0x40 + (y - 1);
lcd_write(add,LCD_WRITE_COM);
lcd_write(byte,LCD_WRITE_DATA);
}
/*====================================================================================
Write String Function
Function prototype: void lcd_dis_str(unsigned char x, unsigned char y, unsigned char *disdata);
Note: x is the row (1-2), y is the column (1-8).
=====================================================================================*/
void lcd_dis_str(unsigned char x, unsigned char y, unsigned charchar *disdata)
{
unsigned char add;
if(((0 == x) || (x > 2)) || ((0 == y) || (y > 16)))
{
return ;
}
add = 0x80 + (x - 1) * 0x40 + (y - 1);
lcd_write(add,LCD_WRITE_COM);
while(*disdata != '\0')
{
lcd_write(*disdata,LCD_WRITE_DATA);
disdata++;
}
}
#if 0
/*===========================================================================
Time display function
============================================================================*/
void lcd_dis_time()
{
lcd_write(0x80 + 4,LCD_WRITE_COM);
lcd_write((hour / 10) + 0x30,LCD_WRITE_DATA);
lcd_write((hour % 10) + 0x30,LCD_WRITE_DATA);
lcd_write((min / 10) + 0x30,LCD_WRITE_DATA);
lcd_write((min % 10) + 0x30,LCD_WRITE_DATA);
lcd_write((sec / 10) + 0x30,LCD_WRITE_DATA);
lcd_write((sec % 10) + 0x30,LCD_WRITE_DATA);
}
#endif
ds18b20.c
[objc] view plain copy View the code snippet derived from my code snippet on CODE
#include
#include
#include
#include "./lcd/lcd.h"
#include "./delay/delay.h"
sbit ds = P1^0;
bit ack = 0;
/*=================================================================
Reset DS18B20
==================================================================*/
void ds_reset()
{
ds = 1;
ds = 0;
delay_us(200);
delay_us(100); //480-960us,800us
ds = 1; //free ds
delay_us(30);
if(0 == ds)
{
ack = 1;
}
else
{
ack = 0;
}
delay_us(200);
delay_us(100);
}
/*=================================================================
Write a byte to the DS18B20
==================================================================*/
void ds_send_byte(unsigned char byte)
{
unsigned char i;
for(i = 0; i < 8; i++)
{
ds = 0;
_nop_();
_nop_();
ds = byte & 0x01;
byte >>= 1;
delay_us(30);
ds = 1;
}
delay_us(30);
}
bit ds_read_bit()
{
bit temp;
ds = 1;
ds = 0;
_nop_();
_nop_();
ds = 1;
temp = ds;
delay_us(30);
return temp;
}
unsigned char ds_read_byte()
{
unsigned char i;
unsigned char j;
unsigned char k;
for(i = 0; i < 8; i++)
{
j = ds_read_bit();
k = (j << 7) | (k >> 1);
}
return k;
}
void main()
{
unsigned char a;
unsigned char disbuf[20];
unsigned int temp;
unsigned int b;
float temperature;
lcd_init();
while(1)
{
ds_reset();
ds_send_byte(0xcc);
ds_send_byte(0x44);
ds_reset();
ds_send_byte(0xcc);
ds_send_byte(0xbe);
a = ds_read_byte();
b = ds_read_byte();
temp = (b << 8) | a;
temperature = (float)temp * 0.0625;
sprintf(disbuf,"Temp is %7.3f",temperature);
lcd_dis_str(1,1,disbuf);
}
}
Previous article:51 single chip microcomputer controls LCD1602 module
Next article:Microcontroller - infrared remote control - code
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- 3.7V-4.2V lithium battery charge and discharge protection chip?
- Xunwei-i.MX6ULL Development Board-Busybox Porting DHCP (Part 2)
- 【EVK-NINA-B400 Evaluation Kit】+New Project
- There is a reason to enter the IT industry early
- Studying Things to Gain Knowledge 04: Finite Angular Displacement is Not a Vector
- Chang'e 4 lands on the moon
- Sinlinx A33 Development Board Linux Interrupt Programming 2--- Program Framework
- Insights on Faster, Better Wi-Fi Deployment in Asia
- 【Project source code】NIOS digital photo frame based on dual SDRAM image cache
- 2.4g antenna impedance Π type circuit debugging