|
我老板也是要我显示波形
在大学计划实验箱上可以完成
AD转换的数据 经过傅立叶变换后
显示出来图象
#include "msp430x44x.h"
//*********************************************************************
//MSP-Test44x Demo LCD matrix dispaly the char and logo(lsd)
//
//
// MSP430F449
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|- ________
// | | | |
// | P2.0|-->| l |
// | . | . | |
// | P2.3| . | C |
// | P2.6| . | |
// | P2.7| . | D |
// | P3.0| . | |
// | . | . | |
// | P3.8|-->|________|
// | |
//
// Yang Rui
// Lierda, Inc
// MAY 2004
// Built with IAR Embedded Workbench Version: 1.26B
//typedef unsigned long DWORD;
typedef unsigned int WORD;
typedef unsigned char BYTE;
//****************************************************************************
//****************************************************************************
//****************************************************************************
#define P2_0_RS 0x01
#define P2_1_RW 0x02
#define P2_2_EN 0x04
#define P2_3_CS1 0x08
#define P2_3_CS2 0x40
#define P2_3_RST 0x80
#define P3_0_DB0 0x01
#define P3_1_DB1 0x02
#define P3_2_DB2 0x04
#define P3_3_DB3 0x08
#define P3_4_DB4 0x10
#define P3_5_DB5 0x20
#define P3_6_DB6 0x40
#define P3_7_DB7 0x80
static unsigned char key_buff;
static unsigned char storo;
static unsigned char stoco;
//****************************************************************************
//****************************************************************************
//****************************************************************************
const BYTE str[248]={0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,0x05,0x05,0x06,0x06,0x07,0x07,0x08,0x08,0x09,0x09,0x0a,
0x14,0x14,0x15,0x15,0x16,0x16,0x17,0x17,0x18,0x18,0x19,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1C,0x1d,
0x1e,0x1e,0x1f,0x1f,0x20,0x20,0x21,0x21,0x22,0x22,0x23,0x23,0x24,0x24,0x24,0x23,0x23,0x22,0x22,
//***************************************************************************************************
//***************************************************************************************************
//***************************************************************************************************
//***************************************************************************************************
//***************************************************************************************************
//***************************************************************************************************
delay(int n)
{
while(n>=0)
{ n--;
_NOP();
}
}
void scan_key_deal(void)
{
unsigned char counter;
unsigned char buffer;
unsigned char com_byte;
unsigned char key_num;
BYTE i;
P1DIR=0x0f;
com_byte=0xff;
P1OUT&=~0x08;
P1OUT&=~0x04;
P1OUT&=~0x02;
l: buffer=P1IN;
for(i=0;i<7;i++)
{
delay(6000);
}
if(0xf0!=(buffer&0xf0)) //judge if the key was press
{
P1OUT|=0x08;
P1OUT|=0x04;
P1OUT|=0x02;
com_byte=0xff;
key_num=0x00;
com_byte=0x02;
for(counter=0x03;counter>0;counter--) //get the key num
{
P1OUT&=~com_byte; //scan the row
if(!(P1IN&BIT4))
break;
key_num++;
if(!(P1IN&BIT5))
break;
key_num++;
if(!(P1IN&BIT6))
break;
key_num++;
if(!(P1IN&BIT7))
break;
key_num++;
com_byte=com_byte<<1;
}
buffer=P1IN;
buffer=P1IN;
key_buff=key_ta××e[key_num]; //get the key value
return;
}
else
goto l;
// flag&=~key_press;
}
void port_ini( void )
{
P3DIR = 0xFF;
P3OUT = 0x00;
P2DIR = 0xFF;
P2OUT = P2_3_CS1 | P2_3_CS2 | P2_3_RST;
P2OUT &=~P2_3_RST;
_NOP();
_NOP();
P2OUT |= P2_2_EN;
_NOP();
_NOP();
P2OUT &=~P2_2_EN;
_NOP();
_NOP();
P2OUT |= P2_3_RST;
_NOP();
_NOP();
}
void write_command( BYTE nByte )
{
P3DIR = 0xFF;
P2OUT |= P2_3_CS1+P2_3_CS2;
P2OUT &=~(P2_0_RS+P2_1_RW);
P3OUT = nByte;
P2OUT |= P2_2_EN;
P2OUT &=~P2_2_EN;
}
void write_char( BYTE nByte, BYTE CS1, BYTE CS2 )
{
P3DIR = 0xFF;
if(CS1) P2OUT |= P2_3_CS1;
else P2OUT &=~P2_3_CS1;
if(CS2) P2OUT |= P2_3_CS2;
else P2OUT &=~P2_3_CS2;
P2OUT |= P2_0_RS;
P2OUT &=~P2_1_RW;
P3OUT = nByte;
P2OUT |= P2_2_EN;
P2OUT &=~P2_2_EN;
}
void clear_lcd( void )
{
BYTE i,j;
for(i=0;i<8;i++)
{
write_command(i|0xB8);
write_command(0x40);
for(j=0;j<128;j++)
{
if(j<=63) write_char(0,1,0);
else write_char(0,0,1);
_NOP();
}
}
}
void display_hz( BYTE *chr, BYTE nRow, BYTE nCol )
{
BYTE i,tmpCol;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<19;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i],0,1);
}
tmpCol++;
}
write_command(0xB8|nRow+1);
tmpCol=nCol;
for(i=0;i<19;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i+19],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i+19],0,1);
}
tmpCol++;
}
}
void display_16_16_icon( BYTE *chr, BYTE nRow, BYTE nCol )
{
BYTE i,tmpCol;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<16;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i],0,1);
}
tmpCol++;
}
write_command(0xB8|nRow+1);
tmpCol=nCol;
for(i=0;i<16;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i+16],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i+16],0,1);
}
tmpCol++;
}
}
void display_char( BYTE *chr, BYTE nRow, BYTE nCol )
{
BYTE i,tmpCol;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<5;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(chr[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[i],0,1);
}
tmpCol++;
}
}
void display_chip(BYTE *ch ,BYTE nRow, BYTE nCol )
{
BYTE i,tmpCol,tmpCol1;
stoco=nCol;
storo=nRow;
write_command(0xB8|nRow);
tmpCol=nCol;
for(i=0;i<2;i++)
{
if(tmpCol<=63)
{
write_command(0x40|tmpCol);
write_char(ch[i],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(ch[i],0,1);
}
tmpCol++;
}
tmpCol1=nCol+7;
for(i=2;i<4;i++)
{
if(tmpCol1<=63)
{
write_command(0x40|tmpCol1);
write_char(ch[i],1,0);
}
else
{
write_command(0x40|(tmpCol1-64));
write_char(ch[i],0,1);
}
tmpCol1++;
}
}
void display_w××e( BYTE *chr, BYTE nCol, BYTE nRow,BYTE b)
{
BYTE tmpCol;
tmpCol=nCol;
write_command(0x3f);
write_command(0xB8|nRow);//显示第一个字节
if(tmpCol<64)
{ write_command(0x40|tmpCol);
write_char(chr[b],1,0);
}
else
{
write_command(0x40|(tmpCol-64));
write_char(chr[b],0,1);
}
delay(999);
// write_command(0x3e);
}
void display_chip2(BYTE *chr,BYTE nRow,BYTE nCol)
{
BYTE tmpCol;
tmpCol=nCol;
write_command(0x3f);
write_command(0xB8|nRow);
write_command(0x40|tmpCol);
write_char(chr[0],1,0);
}
//***************************************************************************************************
//***************************************************************************************************
//***************************************************************************************************
void main(void)
{ BYTE j=0;
int i,a=0,b=0,m,n,d=0;
char da_dis[512];
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
FLL_CTL0 |= XCAP14PF;
port_ini();
clear_lcd();
while(1)
{ b=d;
d=d+8;
a=0;
for(a=0;a<128;a++)
{
da_dis[a]=str[b];
if(b<2048)
b++;
else
b=0;
}
for(i=3;i<128;i++)
{
m=da_dis[i]%8;
n=da_dis[i]/8;
display_w××e((BYTE *)&point[0],131-i,5-n,m);
}
clear_lcd();
display_hz((BYTE *)&Lierda_13_19[0][0],6,30);
display_hz((BYTE *)&Lierda_13_19[1][0],6,60);
display_hz((BYTE *)&Lierda_13_19[2][0],6,90);
for(i=0;i<6;i++)
{
display_chip((BYTE *)&st[0],i,0);
display_chip((BYTE *)&st[1],i,1);
display_chip((BYTE *)&st[2],i,2);
}
}
// WDTCTL=WDTPW+WDT_ARST_1000;
_EINT(); // Ena××e interrupts
while(1)
{
_BIC_SR(LPM3_bits);
_NOP();
_NOP();
}
} |
|