nt5510 LCD进行坐标映射的c语言代码
时间: 2023-09-11 19:06:55 浏览: 51
以下是使用C语言控制NT5510 LCD屏幕进行坐标映射的示例代码:
```C
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// Pin definitions for the NT5510 screen
#define LCD_CS P1_0
#define LCD_SDA P1_1
#define LCD_SCK P1_2
#define LCD_RST P1_3
#define LCD_DC P1_4
// Global variables for the screen dimensions
const uint8_t LCD_WIDTH = 96;
const uint8_t LCD_HEIGHT = 65;
// Function to send a command to the LCD screen
void lcd_command(uint8_t cmd) {
// Set DC low to indicate a command is being sent
LCD_DC = 0;
// Send the command
spi_send(cmd);
}
// Function to send data to the LCD screen
void lcd_data(uint8_t data) {
// Set DC high to indicate data is being sent
LCD_DC = 1;
// Send the data
spi_send(data);
}
// Function to initialize the LCD screen
void lcd_init() {
// Set the pins as outputs
LCD_CS = 1;
LCD_SDA = 1;
LCD_SCK = 1;
LCD_RST = 1;
LCD_DC = 1;
// Reset the screen
LCD_RST = 0;
delay(10);
LCD_RST = 1;
delay(10);
// Send initialization commands
lcd_command(0x21); // Extended commands
lcd_command(0xBC); // Set Vop
lcd_command(0x04); // Vop = 4 * (1 + 4) = 20V
lcd_command(0x14); // Bias system
lcd_command(0x20); // Basic commands
lcd_command(0x0C); // Normal mode
}
// Function to set the cursor position on the screen
void lcd_set_cursor(uint8_t x, uint8_t y) {
lcd_command(0x80 | x); // Set x-coordinate
lcd_command(0x40 | y); // Set y-coordinate
}
// Function to draw a pixel on the screen
void lcd_draw_pixel(uint8_t x, uint8_t y, bool color) {
// Map the x and y coordinates
uint8_t x_mapped = x;
uint8_t y_mapped = y;
if (x > 95) x_mapped = 95;
if (y > 64) y_mapped = 64;
if (x < 0) x_mapped = 0;
if (y < 0) y_mapped = 0;
// Set the cursor position
lcd_set_cursor(x_mapped, y_mapped);
// Draw the pixel
lcd_data(color ? 0xFF : 0x00);
}
// Function to clear the screen
void lcd_clear() {
// Set the cursor position to the top left corner
lcd_set_cursor(0, 0);
// Clear the screen
for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) {
lcd_data(0x00);
}
}
int main() {
// Initialize the LCD screen
lcd_init();
// Clear the screen
lcd_clear();
// Draw a red dot at coordinate (20, 30)
lcd_draw_pixel(20, 30, true);
// Draw a blue dot at coordinate (110, 80)
lcd_draw_pixel(110, 80, true);
return 0;
}
```
该代码使用SPI协议控制NT5510 LCD屏幕,并实现了在给定坐标位置绘制像素点的功能。在绘制像素点之前,该代码使用了简单的坐标映射功能,将超出屏幕范围的坐标值限制在有效范围内。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)