📄 can_gps.lst
字号:
723 {
724 1 data uchar i,*p1;
725 1 bit flag;
726 1 p1=p;
727 1 stop24();
728 1 flag=1; i=0;
729 1 while(flag){
730 2 i++; if(i>250)return;;
731 2 start24();
732 2 wrbyt24(aa);
733 2 flag=get_ACK24();
734 2 if(flag)stop24();
C51 COMPILER V8.05a CAN_GPS 06/20/2008 15:11:44 PAGE 13
735 2 }
736 1 i=loc>>8;
737 1 wrbyt24(i);
738 1 get_ACK24();
739 1 i=loc;
740 1 wrbyt24(i);
741 1 get_ACK24();
742 1 start24();
743 1 wrbyt24(bb);
744 1 get_ACK24();
745 1 for(i=0;i<64;i++) //一页写的字节个数 64个
746 1 {*p1=rdbyt24(); tack24(); p1++;}
747 1 rdbyt24();
748 1 SDA24=1;
749 1 stop24();
750 1 }
751
752 /*----------------------------------------------------------------------*/
753 /*---------------------------------------------------------*/
754
755 void get_24_buff(char *buff,uint n) //n是页数
756 {
757 1 //1片AT24C512有62K字节的容量,可以分成512页,每页64个字节
758 1 //1片AT24C256有32K字节的容量,可以分成512页,每页64个字节
759 1 //1片AT24C128有16K字节的容量,可以分成256页,每页64个字节
760 1 data char *p1;
761 1 data uint base; /*xdata*/
762 1 p1=buff;
763 1 base=0x40+((n-1)<<6); //一页写的字节个数 64个
764 1 if((1536<n)&(n<=2048))read_nbyte24(base,p1,0xa6,0xa7);
765 1 if((1024<n)&(n<=1536))read_nbyte24(base,p1,0xa4,0xa5);
766 1 if(( 512<n)&(n<=1024))read_nbyte24(base,p1,0xa2,0xa3);
767 1 if(n<=512) read_nbyte24(base,p1,0xa0,0xa1);
768 1
769 1 //*(p1+12)=read_abyte24(base+12); //trap_set
770 1 }
771 /*---------------------------------------*/
772 /*n==1--7*/
773 void save_24_buff(char *buff,uint n1)
774 {
775 1 //1片AT24C512有62K字节的容量,可以分成512页,每页64个字节
776 1 //1片AT24C256有32K字节的容量,可以分成512页,每页64个字节
777 1 //1片AT24C128有16K字节的容量,可以分成256页,每页64个字节
778 1 data char *p;
779 1 data uint base,n;
780 1 p=buff;
781 1 n=n1; //ip=*(p+14); //ip1;
782 1 base=0x40+((n-1)<<6); //一页写的字节个数 64个
783 1 if((1536<n)&(n<=2048))write_nbyte24(base,p,0xa6);
784 1 if((1024<n)&(n<=1536))write_nbyte24(base,p,0xa4);
785 1 if(( 512<n)&(n<=1024))write_nbyte24(base,p,0xa2);
786 1 if(n<=512) write_nbyte24(base,p,0xa0);
787 1 //write_abyte24(base+14,ip);
788 1 //write_abyte24(base+15,0x55);
789 1 }
790 /*************************************************************/
791 /********************** LCD **********************************/
792 /*************************************************************/
793 void bit8_serial_input(uchar ix) //~~液晶八位串输入信号行
794 { //~~ix串行输入的数
795 1 idata uchar i;
796 1 P_E=0; //clk=0;
C51 COMPILER V8.05a CAN_GPS 06/20/2008 15:11:44 PAGE 14
797 1 ab=ix;
798 1 for(i=0;i<8;i++){
799 2 P_RW=abit7; //din=abit7; ~~输入最高位
800 2 ab<<=1;
801 2 P_E=1; //~~锁存输入一位
802 2 P_E=0;
803 2 }
804 1 }
805 /*---------------------------------------------------------*/
806 void instruct(uchar dat) //??光标显示,显示控制
807 {
808 1 P_RS=1; //选通
809 1 bit8_serial_input(0xf8);
810 1 bit8_serial_input(dat&0xf0);
811 1 bit8_serial_input(dat<<4);
812 1 P_RS=0; //结束作业
813 1 }
814 void write_abyte(uchar dat) //~~写入一位数据
815 {
816 1 P_RS=1; //读数据--不选通
817 1 bit8_serial_input(0xfa);
818 1 bit8_serial_input(dat&0xf0);
819 1 bit8_serial_input(dat<<4);
820 1 P_RS=0; //结束作业
821 1 }
822 /*写一个汉字到x,Y坐标处其中X为8列y为4行*/
823 void write_word(uint w)
824 {
825 1 write_abyte(w>>8);
826 1 write_abyte(w);
827 1 }
828 /*-------------------------------------------*/
829 /*-------------------------------------------*/
830 dis_hz_str(uchar x, uchar y, uchar *p_hz,uchar number) //~~显示函数可
831 { //~~能是显示文字(也可是字母)串一共
832 1 idata uchar loc,*p; //可显示4行汉字由x决定
833 1 idata uint xi;
834 1 code uchar xline[5]={0,1,3,2,4};
835 1 x=xline[x];
836 1 instruct(home);
837 1 loc=((x<<3)+y-9)|0x80;//~~
838 1 instruct(loc); p=p_hz;
839 1 xi=((*p++)<<8)|*p++;
840 1 while(number--){
841 2 write_word(xi); //*p++;// );
842 2 xi=((*p++)<<8)|*p++; //*p++; xi=xi|*p++;
843 2 }
844 1 }
845 /*显示字母数字在x,y处*/
846 void dis_str(uchar x, uchar y, uchar *str,uchar number)
847 {
848 1 idata uchar loc,*p;
849 1 code uchar xline[5]={0,1,3,2,4};
850 1 p=str;
851 1 x=xline[x];
852 1 instruct(home);
853 1 loc=(16*(x-1)+y-1);
854 1 if(loc&0x01){
855 2 loc/=2;
856 2 instruct(loc|0x80);
857 2 write_abyte(' ');
858 2 }else{
C51 COMPILER V8.05a CAN_GPS 06/20/2008 15:11:44 PAGE 15
859 2 loc/=2;
860 2 instruct(loc|0x80);
861 2 }
862 1 while(number--){
863 2 write_abyte(*p++);
864 2 }
865 1 }
866 /*----------------------------------------*/
867 void screen_cls(void) //清屏
868 {
869 1 instruct(clear);
870 1 delay_us(200); //清屏幕,约1.6ms
871 1 }
872 /*----------------------------------------*/
873 void initial_screen(void)//~~初始化显示屏
874 {
875 1 P_RS=0; //串行--不选通
876 1 P_E=0; //串行方式
877 1 instruct(f_set); //0x30; //8位并行接口 基本指令
878 1 instruct(f_set); //0x30; //8位并行接口 基本指令
879 1 instruct(dis_on); //0x0f; //开启屏幕 光标 闪烁
880 1 instruct(dis_cur); //0x0f; //
881 1 instruct(clear); //0x01); //清屏幕 clear
882 1 delay_us(100);
883 1 instruct(in_mode); //0x06); //光标右移、地址增1 方式
884 1 instruct(home);
885 1 }
886 void b2hex(char ch,char *p)
887 {
888 1 char c1,c2;
889 1 c1=((ch&0xf0)>>4)&0x0f;
890 1 //c1=c1>>4;
891 1 c2=ch&0x0f; //二进制变16进制
892 1 if(c1<=9)c1=c1+'0'; else c1=c1-10+'A';
893 1 if(c2<=9)c2=c2+'0'; else c2=c2-10+'A';
894 1 *p++=c1; *p=c2;
895 1 }
896 //------------------------------------------------------------------
897 void dis_bin(uchar *buff,uchar n)
898 {
899 1 data uchar i,j,ch,*p,*p1;
900 1 idata uchar str[20],str1[3];
901 1 p=buff; p1=str; j=0;
902 1 for(i=0;i<n;i++){
903 2 ch=*p++;
904 2 b2hex(ch,str1); //char ch,char *p)
905 2 *p1++=str1[0]; *p1++=str1[1];
906 2 j=j+2;
907 2 }
908 1 p=buff;
909 1
910 1 for(i=0;i<j;i++)*p++=str[i];
911 1 }
912 /*************************************************************/
913 /********************** 串口 *********************************/
914 /*************************************************************/
915 /*----------------------------------------- */
916 void comm(uchar tt)
917 {
918 1 SBUF=tt;
919 1 EA = 0;
920 1 while(TI==0);
C51 COMPILER V8.05a CAN_GPS 06/20/2008 15:11:44 PAGE 16
921 1 TI=0;
922 1 EA = 1;
923 1 }
924 /*----------------------------------------*/
925 void comm_buff(uchar *tt,n) //从1发送
926 {int i;
927 1 for(i=0;i<n;i++)comm(tt[i]);
928 1 }
929 /*************************************************************/
930 /********************** 其他 *********************************/
931 /*************************************************************/
932 /*---------------------------------------*/
933 void init(void)
934 {
935 1 TR1=1;
936 1 TMOD=0x21; /* T0为方式1,T1方式2*/
937 1 TH1=0x0fd;
938 1 /*11.0592M PCON=0x80加倍 PCON=0x00 不加倍
939 1 0x0fd 19200 9600
940 1 0x0fa 9600 4800
941 1 0x0f4 4800 2400
942 1 0x0e8 2400 1200
943 1 0x0d0 1200 600
944 1 12M PCON=0x80加倍 PCON=0x00 不加倍
945 1 0x0f3 4800 2400
946 1 0x0e6 2400 1200
947 1 0x0cc 1200 600
948 1 */
949 1 PCON=0x80; /*PCON=0x00波特率=4800*/ //PCON=0x80波特率翻倍/*波特率=9600*/
950 1 SCON=0x50;
951 1 SM2=0;
952 1 TR1=1; /*串行口设置为方式1,REN=1*/
953 1 REN=1;
954 1 ES=1;
955 1 EA=1; /*开总中断*/
956 1 RI=0; /*接收数据为开启*/
957 1 }
958 void SYS_init(void)
959 {
960 1 machine_NUM =0x02;
961 1 function_code =0x04;
962 1 data_NUMER =0x10;
963 1
964 1 WD_a[0]=JD_a[0]='"';
965 1 seg_count=0; //逗号计数器
966 1 dot_count=0; //小数点计数器
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -