stc8a--al422B————01,硬件上RE已经接地了。

网友投稿 543 2022-11-10

stc8a--al422B————01,硬件上RE已经接地了。

stc8a--al422B————01,硬件上RE已经接地了。

#include "stc8a8k.h"#include #include "stdlib.h"#include "stdarg.h"#include "string.h" //str函数//22.1184Mhz;#define DataIn P0#define DataOut P2sbit WCK =P1^5;sbit WEN =P1^4;sbit WRST =P1^3;sbit OE =P1^2;sbit RRST =P1^1;sbit RCK =P1^0;//一共8个数据unsigned char tablecode[]={0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF7};//****************************************************************#define Uart1_Rec_Maxlength 100unsigned char Global_Uart1_Rec[Uart1_Rec_Maxlength];//串口1接收空间,100个字节#define Uart1_END_CODE '#' //帧尾自定义符号unsigned char Uart1_Rec_Byte_Length=0;//动态长度,在0-最大Uart1_Rec_Maxlength=100之间unsigned char Uart1_Rec_Frame_Flag=0;//接收一帧标记,=1,接收到一帧数据,=0,没有接受一帧数据unsigned char Global_uart1cmdnum=0;//串口接收到的命令号//************************void UartInit(void); //115200bps@11.0592MHzvoid UART1_SendData(char dat);void UartSendStr(char *p);void Clear_Uart1_Rxbuff(void);//打开写使能和写时钟//P0不断发送数据0x12 0x34 0x56 0x78 0x9A 0xBC 0xDE//打开接收使能和接收时钟;//然后将数据放到P2口;//关闭接收使能//将数据放入数组中;//将数据发送到串口中,打印出来;//打开写时钟,继续输出。void Delay1us() //@22.1184MHz{ unsigned char i; i = 6; while (--i);}void Delay5ms() //@22.1184MHz{ unsigned char i, j; i = 144; j = 157; do { while (--j); } while (--i);}void Delay1ms() //@22.1184MHz{ unsigned char i, j; i = 29; j = 183; do { while (--j); } while (--i);}void Delay5us() //@22.1184MHz{ unsigned char i; i = 35; while (--i);}//初始化脉冲void InitAL422B(){ WEN=1; WRST =1; OE=1; RRST =1; Delay1ms(); WEN=0; WRST =0; Delay1ms(); WRST =1; WEN=1; Delay1ms(); OE=0; RRST =0;//低电平复位,写和读的地址从0开始 Delay1ms(); RRST =1; OE=1; Delay1ms();}//复位,低电平复位void ResetWRST_AL422B(void){ WEN=0; WRST =1; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =1; WEN=1;}//复位,低电平复位void ResetRRST_AL422B(void){ OE=0; RRST =1; RRST =0;RRST =0;RRST =0;RRST =0;RRST =0;RRST =0; RRST =0;RRST =0;RRST =0;RRST =0;RRST =0;RRST =0; RRST =1; OE=1;}//写操作//void I2C_SendByte(unsigned char Byte)//{// unsigned char i;// for(i=0;i<8;i++)// {// I2C_SDA=Byte&(0x80>>i); //把Byte最高位取出来,赋给SDA// I2C_SCL=1;// I2C_SCL=0;// }//}// unsigned char i;// for(i = 0 ; i < 8 ; i++)// {// SDA = dat & (0x80>>i); //依次取出dat的第7、6、5、4……位进行发送// SCL = 1;// SCL = 0;// }//unsigned char I2C_ReceiveByte(void)//{// unsigned char i,Byte=0x00;// I2C_SDA=1;// if(i=0;i<8;i++)// {// I2C_SCL=1;// if(I2C_SDA){Byte|=(0x80>>i);} //相当于如果SDA读取的是1,则把Byte的最高位置1// I2C_SCL=0;// }// return Byte;//} void WriteAL422B(unsigned char temp){ char i=0; WEN=0; DataIn = temp; for(i=8;i>0;i--) { WCK=0; WCK=1;//上升沿,写入数据 I2C_SDA=DataIn&(0x80>>i); Delay1us(); WCK=0; } WCK=0; WEN=1;}// if(I2C_SDA){Byte|=(0x80>>i);} //相当于如果SDA读取的是1,则把Byte的最高位置1unsigned char ReadAL422B(){ unsigned char temp=0x00; char i=0; DataOut=0x00; OE=0; for(i=0;i<8;i++) { RCK=0; //DataOut |=(0x80>>i); // RCK=1;//上升沿,写入数据 RCK=0; }temp = DataOut; RCK=0; OE=1; return temp;}void main(){ int i=0; unsigned char ReadVal=0; P0M0=0x00; P0M1=0x00; P1M0=0x00; P1M1=0x00; P2M0=0x00; P2M1=0x00; P3M0=0x00; P3M1=0x00; P4M0=0x00; P4M1=0x00; P5M0=0x00; P5M1=0x00; P6M0=0x00; P6M1=0x00; P7M0=0x00; P7M1=0x00; InitAL422B(); UartInit();//串口1,波特率115200,定时器2产生,stc8a8k,22.1184Mhz ES = 1; EA = 1; Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); while(1) { WEN=0;//允许写操作 WRST =1; WRST =1; WRST =1; WRST =1; WRST =1; WRST =1; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =1;WRST =1;WRST =1;WRST =1;WRST =1;WRST =1; WEN=1; WEN=0; DataIn = 0xcd; for(i=7;i>=0;i--) { WCK=0; WCK=1;//上升沿,写入数据 I2C_SDA=DataIn&(0x80>>i); Delay1us(); WCK=0; } WEN=1; //ResetRRST_AL422B();//读复位 OE=1; RRST =1; RRST =0;RRST =0;RRST =0; RCK=0; RCK=0; RCK=0; RCK=1; RCK=1; RCK=1; RCK=0;RCK=0;RCK=0; RRST =0;RRST =0;RRST =0; RRST =0;RRST =0; RRST =1; RRST =1; RRST =1; OE=1; OE=0; for(i=0;i<8;i++) { RCK=0; RCK=1;//上升沿,写入数据 RCK=0; } UART1_SendData(DataOut);//串口发送 RCK=0; OE=1; Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); if(P43==0) { Delay5ms(); Delay5ms(); Delay5ms(); Delay5ms(); if(P43==0) { while(P43==0);//等待松下按键 //ResetWRST_AL422B();//写复位 WEN=0;//允许写操作 WRST =1; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =0; WRST =1; WEN=1; WEN=0; DataIn = 0x34; for(i=7;i>=0;i--) { WCK=0; WCK=1;//上升沿,写入数据 I2C_SDA=DataIn&(0x80>>i); Delay1us(); WCK=0; } WEN=1; //ResetRRST_AL422B();//读复位 OE=1; RRST =1; RRST =0;RRST =0;RRST =0;RRST =0;RRST =0;RRST =0; RRST =0;RRST =0;RRST =0;RRST =0;RRST =0;RRST =0; RRST =1; OE=1; ReadVal=ReadAL422B();//读一个数据, UART1_SendData(ReadVal);//串口发送 // Delay1us();Delay1us();Delay1us();Delay1us();Delay1us(); // ReadVal=ReadAL422B();// UART1_SendData(ReadVal);// // Delay1us();Delay1us();Delay1us();Delay1us();Delay1us();// ReadVal=ReadAL422B();// UART1_SendData(ReadVal); // Delay1us();Delay1us();Delay1us();Delay1us();Delay1us(); } } }}//串口1,波特率115200,定时器2产生,void UartInit(void) //115200bps@22.1184Mhz{ SCON = 0x50; //8位数据,可变波特率 AUXR |= 0x01; //串口1选择定时器2为波特率发生器 AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T T2L = 0xFC; //设定定时初值 T2H = 0xFF; //设定定时初值 AUXR |= 0x10; //启动定时器2}//UART1 发送串口数据,一个字节void UART1_SendData(char dat) { ES=0; //关串口中断 SBUF=dat; while(TI!=1); //等待发送成功 TI=0; //清除发送中断标志 ES=1; //开串口中断}//UART1 发送串口数据,字符串void UartSendStr(char *p){ while (*p) { UART1_SendData(*p++); }}//重写putchar函数,可以用printf函数char putchar(char c){ UART1_SendData(c); return c;}//串口1中断服务函数void Uart1Isr() interrupt 4 using 1{ unsigned char cmdtemp=0; if (TI) { TI = 0; } if (RI) { Global_Uart1_Rec[Uart1_Rec_Byte_Length]=SBUF;//将数据放到缓冲区中 Uart1_Rec_Byte_Length++;//递增,不断放到数组中 if(Uart1_Rec_Byte_Length>Uart1_Rec_Maxlength-1) Uart1_Rec_Byte_Length=0; RI = 0; }}//清除串口1的内存void Clear_Uart1_Rxbuff(void){ unsigned char *p,i; p=Global_Uart1_Rec; for(i=0;i

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ORA-55610: Invalid DDL statement on history-tracked table
下一篇:mv-lcd初始化
相关文章

 发表评论

暂时没有评论,来抢沙发吧~