刚开始学430的时候 有很多大神 叫我看手册 我希望大神们可以指导一下看手册到底是什么意思 呢 要注意那些重点呢 因为我写代码到现在都是参考代码 然后不懂的就百度 然后懵懵懂懂走到现在的菜鸟水平 另外求大神们帮忙看个lcd1602显示程序 编译没有问题
#ifndef LCD1602_H_
#define LCD1602_H_
typedef unsigned char uchar;
typedef unsigned int uint;
uchar LCD_Check_busy();
void LCD_Write_Com(unsigned char com);
void LCD_Write_data(unsigned int data);
void LCD_Clear();
void LCDSetCursor(uchar x,uchar y);
void LCDShowStr(uchar x, uchar y,uchar *str);
void LCDOpenCursor();
void LcdCloseCursor();
void LCD_Init();
void Init_Clock();
//**************????????????*****************
//**************????????????*****************
#define RS BIT0
#define RW BIT1
#define E BIT2
#define data_dir P1DIR
#define data_out P1OUT //|= 0xf0 //????????????
#define data_in P1IN//7???????????????
//*************************************
#define RS_1 P1OUT |= RS //rs = 1
#define RS_0 P1OUT &= ~RS//rs = 0
#define RW_1 P1OUT |= RW;
#define RW_0 P1OUT &= ~RW;
#define E_1 P1OUT |= E //e = 1
#define E_0 P1OUT &= ~E //e = 0
//*****************????????????******************
//??????us
void delay_1us(uint i)
{
asm("nop");
}
void delay_us(uint i)
{
uint j;
for(j=0;j<i;j++)
delay_1us(j);
}
//??????ms
void delay_1ms()
{
uint i;
for(i=0;i<1140;i++);
}
void delay_ms(uint i)
{
uint j;
for(j=0;j<i;j++)
delay_1ms(j);
}
void Init_Clock()
{
BCSCTL1 = RSEL2 + RSEL1+ RSEL0;
BCSCTL2 = SELM1 + SELS;
}
uchar LCD_Check_busy() //???????????? ??????P2??????????????? D7?????????????????????
{
char busy = 0;
RS_0;
RW_1;
E_1;
delay_ms(50);
data_dir &= ~BIT7; //?????????????????????
busy = data_in & BIT7;
data_dir |= BIT7;
data_out &= ~BIT7;
E_0;
return busy;
}
void LCD_Write_Com(unsigned char com)//????????????
{
//while(LCD_Check_busy());
RS_0;
RW_0;
data_out &= 0x0f; //????????????
data_out |= com & 0xf0; //????????????
E_1;
delay_ms(50);
E_0;
com = com << 4;
data_out &= 0x0f;
data_out |= com & 0xf0;
E_1;
delay_ms(50);
E_0;
}
void LCD_Write_data(unsigned int data)//?????????????????????
{
//while(LCD_Check_busy());
RS_1;
RW_0;
data_out &= 0x0f;
data_out |= data & 0xf0;
E_1;
delay_ms(50);
E_0;
data <<= 4;
data_out &= 0x0f;
data_out |= data & 0xf0;
E_1;
delay_ms(5);
E_0;
}
void LCD_Clear()
{
LCD_Write_Com(0x01);
delay_ms(50);
}
void LCDSetCursor(uchar x,uchar y) //??????????????????
{
uchar addr;
if(y == 0)
addr = 0x00 + x;
else
addr = 0x40 +x;
LCD_Write_Com(addr | 0x80);
}
void LCDShowStr(uchar x, uchar y,uchar *str)//???????????????
{
LCDSetCursor(x,y);
while (*str != '\0')
LCD_Write_data(*str++);
}
void LCDOpenCursor()//????????????
{
LCD_Write_Com(0x0F);
}
void LcdCloseCursor()//??????????????????
{
LCD_Write_Com(0x0C);
}
void LCD_Init()
{
delay_ms(500);
delay_ms(500);
LCD_Write_Com(0x28);//0x28 = 0010 1000 ??????????????????16*2?????????5*7?????? ???4????????????
delay_ms(50);
LCD_Write_Com(0x28);
delay_ms(50);
LCD_Write_Com(0x28);
delay_ms(50);
E_1;
delay_us(10);
E_0;
delay_ms(50);
LCD_Write_Com(0x28);
delay_ms(500);
LCD_Write_Com(0x01);
LCD_Write_Com(0x06);
delay_us(40);
LCD_Write_Com(0x0C);
delay_ms(5);
}
#endif
#include <msp430.h>
#include "lcd1602.h"
void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1SEL |= 0X00;
P1DIR |=(BIT0|BIT1|BIT2|BIT4|BIT5|BIT6|BIT7);
P1OUT &= ~(BIT0|BIT1|BIT2|BIT4|BIT5|BIT6|BIT7);
Init_Clock();
LCD_Init();
LCD_Clear();
LCDShowStr(0,0,"C X H");
LCDShowStr(0,1,"hello word!");
while(1);
}
一开始的时候可以显示字符 但是对比度很暗
但是一断电在插上USB口就会乱码 然后就是第二行可以显示 第一行不行
然后现在是跑程序 它也不显示了
我觉得大约是我判忙函数的问题 但是同一个程序 我试着注释掉我的判忙函数但是也不行 感觉整个人都斯巴达了 |