#include <msp430.h>
/*
* main.c
*/
void zhiling(void);
void mingling(char num);
void shuju(char x,char y,char *s);
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR=0xf0;
P2DIR=0x18;
while(1)
{
zhiling();
shuju(0,1,"a");
shuju(1,1,"hello");
_delay_cycles(500000);
}
return 0;
}
void zhiling(void)
{
mingling(0x28);
mingling(0x0c);
mingling(0x01);
_delay_cycles(2000);
}
void mingling(char num)
{
_delay_cycles(16);
P2OUT=0x10;
P1OUT &=0x00;
P1OUT=(num&0xf0);
P2OUT &= ~BIT4;
P2OUT=0x10;
P1OUT &=0x00;
P1OUT=((num<<4)&0xf0);
P2OUT &=~BIT4;
}
void shuju(char x,char y,char *s)
{
_delay_cycles(16);
char data;
if(x==0)
mingling(0x80+y);
else
mingling(0xc0+y);
for(;*s;s++)
{
data=*s;
P2OUT=0x18;
P1OUT &=0x00;
P1OUT=(data&0xf0);
P2OUT &=~BIT4;
P2OUT=0x18;
P1OUT &=0x00;
P1OUT=((data<<4)&0xf0);
P2OUT &=~BIT4;
}
}
就在调试数据函数的时候,我发现第一遍数据都是对的,显示也正常,但到第二遍的时候data的值就不是原来的“a”与“hello”了,这是怎么回事?
此帖出自
小平头技术问答
一周热门 更多>