|
main.c
//2012年7月28日,已完成
#include<msp430g2553.h>
#include"header.h"
const char table1[] = {"I LOVE XIAOZHU"};
char flag_time = 0;
long TIME0 = 0, TIME1 = 0; //存放时间的函数
long L_juli = 0;
long l = 0;
char ge,shi,bai,qian;
//时钟初始化
void CLK_Init(void)
{
if (CALBC1_8MHZ ==0xFF || CALDCO_8MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_8MHZ; // Set range
DCOCTL = CALDCO_8MHZ; // Set DCO step + modulation */
BCSCTL2 |= 0X02; //SMCLK为DCO的2分频,4M
}
//端口初始化
void GPIO_Init(void)
{
P1DIR |= 0xf0;
P2DIR |= 0x03;
//P2.3作为捕获输入
P2SEL |= 0x08;
P2DIR |= 0x04; //P2.2作为触发端,设为输出
P2OUT &= 0xfb; //P2.2输出低电平
P1IES = 0x08; //P1.3为下降沿触发中断
P1IE = 0x08; //P1.3中断允许
P1IFG = 0x00; //清除中断标志
}
//定时器TIME1_A3初始化函数
void TIME1_A3_Init(void)
{
TA1CTL |= TASSEL1 + MC_2; //SMCLK作为时钟源,连续计数模式
TA1CCTL0 |= CM_3 + CCIS_1 + SCS + CAP + CCIE; //上升沿与下降沿都捕获,
//输入源为CCI0B,同步捕获模式,使能中断
}
//主函数
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗定时器
CLK_Init();
GPIO_Init();
TIME1_A3_Init();
LCD5110_Init();
LCD5110_Clear_All();
LCD5110_SET_XY(0, 1);
Write_String(table1);
LCD5110_BL_H;
_EINT(); //中断使能
while(1)
{
LPM0;
_NOP();
}
}
//定时器Timer1_A CCR0中断服务函数
#pragma vector = TIMER1_A0_VECTOR
__interrupt void TIMER1_A0__ISR(void)
{
if (flag_time == 0)
{
P2OUT &= ~0x04; //P2.2输出低电平
TIME0 = TA1CCR0;
flag_time ++;
}
else
{
TIME1 = TA1CCR0;
flag_time = 0;
if (TIME1 > TIME0)
{
TIME1 = TIME1 - TIME0;
}
else
{
TIME1 = TIME1 + (65535 - TIME0);
}
l = TIME1*170;
L_juli = l/4000;
ge = L_juli % 10 + 48;
shi = (L_juli/10) % 10 + 48;
bai = (L_juli/100) % 10 + 48;
qian = (L_juli/1000) % 10 + 48;
LCD5110_Clear(4);
LCD5110_SET_XY(0, 4);
Write_Char(qian);
Write_Char(bai);
Write_Char(shi);
Write_Char(ge);
}
}
//P1口中断服务函数
#pragma vector = PORT1_VECTOR
__interrupt void P1_ISR(void)
{
switch (P1IFG)
{
case 0x01:
P1IFG &= ~0x01;
break;
case 0x02:
P1IFG &= ~0x02;
break;
case 0x04:
P1IFG &= ~0x04;
break;
case 0xF8:
P2OUT |= 0x04; //P2.2输出高电平
P1IFG &= ~0x08;
break;
case 0x10:
P1IFG &= ~0x10;
break;
case 0x20:
P1IFG &= ~0x20;
break;
case 0x40:
P1IFG &= ~0x40;
break;
case 0x80:
P1IFG &= ~0x80;
break;
default :
P1IFG = 0x00;
break;
}
}
header.h
#ifndef _HEADER_H
#define _HEADER_H
/************************************************************
LCD函数声明
************************************************************/
#define LCD5110_CE_H P1OUT |= 0x80 //5110片选P1.7置位
#define LCD5110_CE_L P1OUT &= 0x7f //5110片选P1.7复位
#define LCD5110_DC_H P1OUT |= 0x40 //5110数据命令选择端P1.6置位
#define LCD5110_DC_L P1OUT &= 0xbf //5110数据命令选择端P1.6复位
#define LCD5110_DIN_H P1OUT |= 0x20 //5110数据输入端P1.5置位
#define LCD5110_DIN_L P1OUT &= 0xdf //5110数据输入端P1.5复位
#define LCD5110_CLK_H P1OUT |= 0x10 //5110数据命令选择端P1.4置位
#define LCD5110_CLK_L P1OUT &= 0xef //5110数据命令选择端P1.4复位
#define LCD5110_BL_H P2OUT |= 0x02 //5110背光控制端P2.1置位
#define LCD5110_BL_L P2OUT &= 0xfd //5110背光控制端P2.1复位
#define LCD5110_RES_H P2OUT |= 0x01 //5110背光控制端P2.0置位
#define LCD5110_RES_L P2OUT &= 0xfe //5110背光控制端P2.0复位
#define LCD_CMD 0x00
#define LCD_DATA 0xff
extern void DELAYms(unsigned int time); //延时ms函数
extern void LCD5110_SET_XY(char x, char y); //写坐标函数
extern void LCD5110_Init(void); //屏幕初始化
extern void LCD5110_Clear(unsigned char L); //清除指定行
extern void LCD5110_Clear_All(void); //清除全屏
extern void Write_Char(char c); //写一个ASCII字符
extern void Write_String(const char *p); //写字符串
/*************************************************************
ASCII字符库 8*6
*************************************************************/
//const char ASCII_8X6[92][6];
#endif
55110.c
#include<msp430g2553.h>
#include<string.h>
#include"header.h"
/*************************************************************
ASCII字符库 8*6
*************************************************************/
const char ASCII_8X6[92][6]=
{
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp
{ 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // !
{ 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // "
{ 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
{ 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $
{ 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // %
{ 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // &
{ 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // '
{ 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // (
{ 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // )
{ 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // *
{ 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // +
{ 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // ,
{ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
{ 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // .
{ 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // /
{ 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0
{ 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1
{ 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2
{ 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3
{ 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4
{ 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
{ 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6
{ 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7
{ 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
{ 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9
{ 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // :
{ 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ;
{ 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // <
{ 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // =
{ 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // >
{ 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
{ 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @
{ 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C
{ 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D
{ 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F
{ 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G
{ 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H
{ 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I
{ 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J
{ 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K
{ 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L
{ 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M
{ 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N
{ 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O
{ 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P
{ 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q
{ 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R
{ 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S
{ 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T
{ 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U
{ 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V
{ 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W
{ 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X
{ 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y
{ 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
{ 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [
{ 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55
{ 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ]
{ 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
{ 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
{ 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // '
{ 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
{ 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c
{ 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d
{ 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f
{ 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g
{ 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h
{ 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i
{ 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j
{ 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k
{ 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l
{ 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n
{ 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
{ 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p
{ 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q
{ 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r
{ 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s
{ 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t
{ 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u
{ 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v
{ 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w
{ 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
{ 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y
{ 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z
{ 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines
};
void DELAYms(unsigned int time)
{
unsigned int i,n;
for (n = time; n > 0; n --)
{
for (i = 4000; i > 0; i --)
{
_NOP();
}
}
}
//写1字节数据或命令函数
void LCD5110_WriteByte(char WriteData, char Cmd_Data)
{
unsigned int i;
LCD5110_CE_L;
if (Cmd_Data)
{
LCD5110_DC_H;
}
else
LCD5110_DC_L;
for (i = 0; i < 8; i ++)
{
if (WriteData & 0x80)
{
LCD5110_DIN_H;
}
else
LCD5110_DIN_L;
WriteData <<= 1;
LCD5110_CLK_L;
_NOP();
LCD5110_CLK_H;
}
LCD5110_DC_H;
LCD5110_CE_H;
LCD5110_DIN_H;
//P1IFG = 0X00;
}
//写入坐标地址
void LCD5110_SET_XY(char x, char y)
{
LCD5110_WriteByte(0x40|y, 0); //设置y轴的坐标,y的范围为0~5
LCD5110_WriteByte(0x80|x, 0); //设置x轴的坐标,x的范围为0~83
}
//液晶屏初始化
void LCD5110_Init(void)
{
LCD5110_RES_L;
DELAYms(10);
LCD5110_RES_H;
LCD5110_WriteByte(0x21, 0); //功能设置为拓展指令集
LCD5110_WriteByte(0xc6, 0); //设置液晶偏置电压
LCD5110_WriteByte(0x06, 0); //温度校正
LCD5110_WriteByte(0x13, 0); //偏置为1:48
LCD5110_WriteByte(0x20, 0); //功能设置为基本指令集
LCD5110_WriteByte(0x0c, 0); //设置显示模式为普通模式
}
//清除指定行
void LCD5110_Clear(unsigned char L)
{
char i = 0;
if (L < 6)
{
LCD5110_SET_XY(0, L);
for (i = 0; i < 84; i ++)
{
LCD5110_WriteByte(0x00, LCD_DATA);
}
}
}
//整个屏幕清除
void LCD5110_Clear_All(void)
{
unsigned char i;
for (i = 0; i < 6; i ++)
{
LCD5110_Clear(i);
}
}
//写一个字符的函数
void Write_Char(char c)
{
unsigned char i;
unsigned char j;
i = c - 0x20;
for (j = 0; j < 6; j ++)
{
LCD5110_WriteByte(ASCII_8X6[i][j], LCD_DATA);
}
}
void Write_String(const char *p)
{
unsigned char i;
for (i = 0; i < strlen(p); i ++)
{
Write_Char(p[i]);
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
该献的血还是要献的。你不献他不献。难道让我去献? --- 出自坛友:lovejp1981
|