/********************************************************************
倒车雷达。
UCFG1=0X63,使能RPE,BOE.震荡器选择内部RC震荡器(7.73MHz)
*********************************************************************/
/*
a 实验板 a--g,DP对应P0.7-P0.0;
----- 数码管共阳极 gfe dcba abcd efg dot
|f |b 对应数字: 0(abcdef): 1100 0000 0xC0 0000 0011 0x03 ,XIAN SHI DOT,zui hou yi wei 0;
| g | 1(bc): 1111 1001 0xF9 1001 1111 0x9f
------ 2(abdeg): 1100 0100 0xA4 0010 0101 0x25
|e |c 3(abcdg): 1011 0000 0xB0 0000 1101 0x0d
| | .. 4(bcfg): 1001 1001 0x99 1001 1001 0x99
------ .. 5(acdfg): 1001 0010 0x92 0100 1001 0x49
d 6(acdefg): 1000 0010 0x82 0100 0001 0x41
7(abc): 1111 1000 0xF8 0001 1111 0x1f
8(abcdefg): 1000 0000 0x80 0000 0001 0x01
9(abcdfg): 1001 0000 0x90 0000 1001 0x09
数码管动态显示数字,保持时间1-5ms,这里利用了眼睛的视觉特性,在这里取适中3ms。'p' abefg--0011 0001 0x31
*/
#include<stdio.h>
#include<reg922.h>
#include"uart.h"
//#include"i2c.h"
#include <INTRINS.H>
#include<ctype.h>
#define RED_LED XTAL1
#define GREEN_LED XTAL2
#define ON 0
#define OFF 1
#define SPK TxD
#define nCS XTAL2
#define SCK INT0
#define SIN SCL
#define SOUNDHIGH 20
#define SOUNDLOW 100
enum _sound_flag{tingche=1,weixian=10,jingshi=50,anquan=100}sound_flag;
void t0_init();
//uint sound_flag;
void ChuLi_Disp_Data();
//void Delay(uint);
//void Sound_Alarm(); //GAO JIN YING HANG SHU;
void ByteTo_M35055(uchar byte_to_m35055);//XIE BYTE SHU JU JIN M35055
void DataTo_M35055();
/*SPI function*/
void Transfer16Bit(int sendData);
void DelayNus(int n);
uchar databyte[3]; //JIE SHOU SAN ZI JIE;
float nearest_juli; // ZUI JIN JU LI;
uint unSoundSpace;
uint byte_wei=1; //ZI JIE WEI;
uchar uchar_disp_wei;
uint first_suzi,sec_suzi,thir_suzi;
uchar disp_data[10]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09};
int to_m35055_no=1;
bit show_flag;
uchar first_char,sec_char,thir_char,forth_char;
uchar first_detector,forth_detector;
//M35055 ZI FU DING YI 0(0X20), 1(0X21), 2,3,4,5,6,7,8,9 dot(0x1E)
//uchar M35055_char[10]={0x20.0x21};
void main(void)
{
//start_data_flag=0;
uchar_disp_wei=0x00;
databyte[2]=0x80;
first_suzi=0;
sec_suzi=0;
thir_suzi=0;
unSoundSpace=0;
SPK=OFF;
/*Port configation*/
P3M1 = 3; //DING YI RED_LED,GREEN_LED;
P3M2 = 3;
P1M1 = 0X00; //DING SHU MA GUAN SHU CHU;
P1M2 = 0X00;
//PEI ZHI SCK,DIN WEI KAI LOU SHU CHU
P1M1|=0X0C;
P1M2|=0X0C;
//P1M1
P0M1 = 0xFF;
P0M2 = 0xFF;
/*P1 value*/
SPK = 1;
SCK = 1;//HIGH; //UART clock pin
SIN = 1;//HIGH; //UART data pin
/*P3 value*/
nCS = 0;//HIGH;
RED_LED = 1;//LED_OFF;
uart_init();
t0_init();
// nCS=0;
//Transfer16Bit(0x00f8);
// Transfer16Bit
while(1)
{ //nCS=1;
if(show_flag)
{
// /*
show_flag=0;
if(to_m35055_no==1)
{
XTAL2=0;
Transfer16Bit(0x00f8);
Transfer16Bit(0x3f40); //2
Transfer16Bit(0x00ff);
Transfer16Bit(0x00ff); //8
Transfer16Bit(0x00ff);
Transfer16Bit(0x00ff);
// Transfer16Bit(0x00ff);
//Transfer16Bit(0x00ff); //10
//Transfer16Bit(0x00ff);
if(nearest_juli<0.3)
{
Transfer16Bit(0x0143); //12 //xian shi 'stop'
Transfer16Bit(0x0144);
Transfer16Bit(0x013f); //14
Transfer16Bit(0x0140);
Transfer16Bit(0x01ff);
}
else
if(nearest_juli>3.15)
{
Transfer16Bit(0x01ff); //12
Transfer16Bit(0x01ff);
Transfer16Bit(0x01ff); //14
Transfer16Bit(0x01ff);
Transfer16Bit(0x01ff);
}
else
{
Transfer16Bit(0x0100+0x20+first_suzi); //12
Transfer16Bit(0x011e);
Transfer16Bit(0x0100+0x20+sec_suzi); //14
Transfer16Bit(0x0100+0x20+thir_suzi);
Transfer16Bit(0x015d);
}
Transfer16Bit(0x00ff);
// Transfer16Bit(0x0100+first_detector); //10
// Transfer16Bit(0x0100+forth_detector);
Transfer16Bit(0x00ff);
Transfer16Bit(first_char);
Transfer16Bit(sec_char);
Transfer16Bit(thir_char);
Transfer16Bit(forth_char);
}
while(to_m35055_no>17&&to_m35055_no<243)
{
Transfer16Bit(0x01ff);
//Transfer16Bit(0x0200);
// Transfer16Bit(0x0400);
//Transfer16Bit(0x0740);
}
//
if(to_m35055_no==243)
{
Transfer16Bit(0x0480); //F0
//Transfer16Bit(0x00f1);
Transfer16Bit(0x1f0f); //244 F1
Transfer16Bit(0x1f20); //F2
Transfer16Bit(0x0001); //246 F3
Transfer16Bit(0x0000); //F4
Transfer16Bit(0x0088); //248 F5
Transfer16Bit(0x201B); //F6
Transfer16Bit(0x0800); //250 //F7
}
if(to_m35055_no==251)
{
Transfer16Bit(0x3F40);
to_m35055_no=1;
XTAL2=1;
}
// */
//databyte[2]=0xd2;
//ChuLi_Disp_Data();
//Sound_Alarm();
//DataTo_M35055();
}
}
// while(1){;}
}
//jie shou UART xin hao ,jiang san zi jie fen bie fang ru shu zu databyt;
void rx_interrupt() interrupt 4
{
uchar ucTemp;
if(RI) //JIE SHOU ZHONG DUAN ;
{
ucTemp=SBUF;
if((ucTemp&0xF0)==0x50) //kai shi jie shou san zi jie shu ju;
{
byte_wei=0;
databyte[byte_wei++]=ucTemp;
}
else
if(byte_wei>0)
databyte[byte_wei++]=ucTemp;
if(byte_wei==3) //fang zhi cheng xu fa sheng cuo wu;
{
show_flag=1;
byte_wei=0;
ChuLi_Disp_Data();
}
RI=0;
}
}
// pei zhi t0 ding shi;
void t0_init()
{
EA=0;
TMOD|=0X01; //T0 GONG ZUO ZAI MO SHI 1,16 WEI DING SHI QI
TMOD&=0XF1;
TAMOD&=0XFE; //T0M2=0;
TH0=0XFA; //DING SHI YAN SHI 1ms;(2/FOSC)*2*(-T0)=1ms,fosc=7.3728MHz,
TL0=0X35; //yi tiao zhi ling XU 2 ge ji qi zhou qi;T0=-1843.2
TF0=0;
ET0=1;
TR0=1; //kai shi ding shi qi T0;
EA=1;
}
//ding shi xian shi cheng xu
void t0_interrupt() interrupt 1
{
//TF0=1; // YING JIAN ZI DONG QING LING;
//TH0=0XA0;
//TL0=0X35;
uchar_disp_wei++;
switch(uchar_disp_wei)
{
case 0x1:
//if(nearest_juli>=0&&nearest_juli<=3.15)
if(nearest_juli>=0&&nearest_juli<=3.15) //ju li da yu huo deng yu 0.3m
{
// P0=0XFF;
P0=nearest_juli<0.3?0xfd:disp_data[first_suzi]&0xFE; //xian shi di yi wei shu zi,ling jia shang dot xian shi
}
P1&=0X7F; //P1.7 ZHI LING
P1|=0X50;
break;
case 0x2:
// if(nearest_juli<0.3)
//{
// P0=0X31; //di er wei xian shi 'p'
// }
// else
if(nearest_juli>=0&&nearest_juli<=3.15)
{
P0=nearest_juli<0.3?0x31:disp_data[sec_suzi]; // xian shi di er wei shu zi
}
P1&=0XBF; //P1.6 ZI LING
P1|=0X90;
break;
case 0x3:
// if(nearest_juli<0.3)
// {
// P0=0XFD; //di san wei xian shi '-'
// }
if(nearest_juli>=0&&nearest_juli<=3.15)
{
P0=nearest_juli<0.3?0xfd:disp_data[thir_suzi]; //xian shi de san wei shu zi
}
P1&=0XEF; //P1.4 Z