我最近被要求做一个带有温度传感器的大学项目。在 proteus 上模拟它很容易,一切都很好。然后我试图把它变成硬件,但什么也没发生。液晶显示器可以工作,但我的液晶显示器上实际上并没有出现任何数据,尽管液晶显示器在我的 arduino 上运行良好。
我正在使用一个 4 MHz 晶体振荡器,它带有 2 个 22pf 电容器,与 atmega16 的 12 和 13 针相连。
这是我的代码:
sbit LCD_RS at PORTC2_bit;
sbit LCD_EN at PORTD6_bit;
sbit LCD_D4 at PORTC4_bit;
sbit LCD_D5 at PORTC5_bit;
sbit LCD_D6 at PORTC6_bit;
sbit LCD_D7 at PORTC7_bit;
sbit LCD_RS_Direction at DDC2_bit;
sbit LCD_EN_Direction at DDD6_bit;
sbit LCD_D4_Direction at DDC4_bit;
sbit LCD_D5_Direction at DDC5_bit;
sbit LCD_D6_Direction at DDC6_bit;
sbit LCD_D7_Direction at DDC7_bit;
const unsigned short VREF = 5.00;
unsigned int temp_res = 0;
float temp;
char txt[15];
void main() {
DDA7_bit = 0; // Configure PA7 pin as input
ADC_Init(); // Initialize ADC
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Temperature :");
Lcd_Chr(2,8,223); // Different LCD displays have different
// char code for degree
Lcd_Chr(2,9,'C'); // Display "C" for Celsius
temp_res = 0;
do {
temp_res = ADC_Get_Sample(7); // Get 10-bit results of AD conversion
temp = (temp_res * VREF)/10.240; // Calculate temperature in Celsius
// change Vref constant according
// to the power supply voltage
FloatToStr(temp, txt); // Convert temperature to string
txt[4] = 0;
Lcd_Out(2,3,txt); // Write string in second row
Delay_ms(1000);
} while(1);
}