代码:/*
* File: main.c
* Author: Administrator
*
* Created on 2024?5?7?, ??8:01
*/
#include <xc.h>
//CONFIG1L?????
#pragma config RETEN = OFF //?????????
#pragma config INTOSCSEL = HIGH //???? LF-INTOSC ??????
#pragma config SOSCSEL = DIG //SOSC???? SCLKI?????? RC0 ?RC1 ??I/O
#pragma config XINST = OFF //??????????????????????? ??????
// CONFIG1H
#pragma config FOSC = HS1 //4 MHz - 16 MHz ??????HS????????
#pragma config PLLCFG = ON //??PLL x4???8M???4????32MHz????
#pragma config FCMEN = OFF //???????????
#pragma config IESO = OFF //??????
// CONFIG2L
#pragma config PWRTEN = OFF //??????
#pragma config BOREN = SBORDIS //?????????
#pragma config BORV = 3 //?????1.8v????
#pragma config BORPWR = ZPBORMV //??ZPBORMV???BORMV
// CONFIG2H
#pragma config WDTEN = OFF //????
//#pragma config WDTEN = SWDTDIS //?????WDT???SWDTEN?
#pragma config WDTPS = 256 //??????1:256?????1.024s
// CONFIG3H
#pragma config CANMX = PORTB //CAN??????? RB2 ? RB3
#pragma config MSSPMSK = MSK7 //?? 7 ???????
#pragma config MCLRE = ON //??MCLR??????
// CONFIG4L
#pragma config STVREN = ON // ???/????
#pragma config BBSIZ = BB2K // ????????2K
// CONFIG5L
#pragma config CP0 = OFF //00800-01FFF?????
#pragma config CP1 = OFF //02000-03FFF?????
#pragma config CP2 = OFF //04000-05FFF?????
#pragma config CP3 = OFF //06000-07FFF?????
// CONFIG5H
#pragma config CPB = OFF //????????
#pragma config CPD = OFF //EEPROM??????
// CONFIG6L
#pragma config WRT0 = OFF // 00800-01FFF ???????
#pragma config WRT1 = OFF // 02000-03FFF ???????
#pragma config WRT2 = OFF // 04000-05FFF ???????
#pragma config WRT3 = OFF // 06000-07FFF ???????
// CONFIG6H
#pragma config WRTC = OFF //??????????
#pragma config WRTB = OFF //????????
#pragma config WRTD = OFF //EEPROM???????
// CONFIG7L
#pragma config EBTR0 = OFF //00800-01FFF????????
#pragma config EBTR1 = OFF //02000-03FFF????????
#pragma config EBTR2 = OFF //04000-05FFF????????
#pragma config EBTR3 = OFF //06000-07FFF????????
// CONFIG7H
#pragma config EBTRB = OFF //????????
#define uchar unsigned char
#define uint unsigned int
#define DA_1 RC0=1
#define DA_0 RC0=0
#define WR_1 RC2=1
#define WR_0 RC2=0
#define CS_1 RC4=1
#define CS_0 RC4=0
#define Smg_a 0x80
#define Smg_b 0x40
#define Smg_c 0x20
#define Smg_d 0x01
#define Smg_e 0x02
#define Smg_f 0x08
#define Smg_g 0x04
#define Smg_dp 0x10
#define Bmp0Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f
#define Bmp1Map Smg_b | Smg_c
#define Bmp2Map Smg_a | Smg_b | Smg_d | Smg_e | Smg_g
#define Bmp3Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_g
#define Bmp4Map Smg_b | Smg_c | Smg_f | Smg_g
#define Bmp5Map Smg_a | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp6Map Smg_a | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp8Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define Bmp9Map Smg_a | Smg_b | Smg_c | Smg_d | Smg_f | Smg_g
#define Bmp7Map Smg_a | Smg_b | Smg_c
#define BmpAMap Smg_a | Smg_b | Smg_c | Smg_e | Smg_f | Smg_g
#define BmpBMap Smg_c | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpCMap Smg_a | Smg_d | Smg_e | Smg_f
#define BmpDMap Smg_b | Smg_c | Smg_d | Smg_e | Smg_g
#define BmpEMap Smg_a | Smg_d | Smg_e | Smg_f | Smg_g
#define BmpFMap Smg_a | Smg_e | Smg_f | Smg_g
const unsigned char SegCode[] = {Bmp0Map,Bmp1Map,Bmp2Map,Bmp3Map,Bmp4Map,Bmp5Map,Bmp6Map,Bmp7Map,Bmp8Map,Bmp9Map,BmpAMap,BmpBMap,BmpCMap,BmpDMap,BmpEMap,BmpFMap};
unsigned char DpyNum[6] = {Smg_g,Smg_g,Smg_g,Smg_g,Smg_g,Smg_g}; //?????
unsigned int i;
void delay(void)
{
uint j;
for(j=0;j<10;j++);
}
void COMMAND_HT1621(unsigned char comm)
{
//unsigned char i;
CS_0;
delay();
WR_0;
delay();
for(i=0;i<3;i++)//???
{
if((0x04<<i)&0x04) DA_1; //100
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<9;i++)//?????
{
if((comm<<i)&0x80) DA_1; //100
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
CS_1;
delay();
}
void HT1621_Display(void)
{
//unsigned char i;
CS_0;//??CS
delay();
WR_0;
delay();
for(i=0;i<3;i++) //???
{
if((0x05<<i)&0x04) DA_1;
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<6;i++) //???
{
if((20<<i)&0x20) DA_1;//20?? SEG??
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<8;i++) //???
{
if((DpyNum[5]<<i)&0x80) DA_1;
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<8;i++) //???
{
if((DpyNum[4]<<i)&0x80) DA_1;
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<8;i++) //???
{
if((DpyNum[3]<<i)&0x80) DA_1;
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<8;i++) //???
{
if((DpyNum[2]<<i)&0x80) DA_1;
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<8;i++) //???
{
if((DpyNum[1]<<i)&0x80) DA_1;
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
for(i=0;i<8;i++) //???
{
if((DpyNum[0]<<i)&0x80) DA_1;
else DA_0;
delay();
WR_0;
delay();
WR_1;
delay();
}
CS_1;//??CS
delay();
}
void LCD_Init(void)
{
COMMAND_HT1621(0x01);//SYS EN
COMMAND_HT1621(0x03);//LCD ON
COMMAND_HT1621(0x29);//4 COM牋1/3 BIAS
HT1621_Display(); //clear screen
}
/***************************************************************************************
牋* @?????牋 牋????IO??????
***************************************************************************************/
void main(void)
{
/***********************************??IO???***************************************/
TRISCbits.TRISC4=0; //PORD4配置为输出
TRISCbits.TRISC2=0; //PORE1配置为输出
TRISCbits.TRISC0=0; //PORE1配置为输出
LCD_Init();
DpyNum[0] = Smg_a|Smg_d|Smg_g;//"?"
DpyNum[1] = SegCode[2];
DpyNum[2] = SegCode[4];
DpyNum[3] = SegCode[6];
DpyNum[4] = SegCode[8];
DpyNum[5] = SegCode[0];
HT1621_Display();
while(1)
{
}
}
效果图
|