| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 996 人关注过本帖
标题:写卡程序,读的部分很成功,写的部分不成功,应该如何编程?
只看楼主 加入收藏
h1357951
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2017-5-2
结帖率:100%
收藏
 问题点数:0 回复次数:0 
写卡程序,读的部分很成功,写的部分不成功,应该如何编程?
#include <reg52.h>                                    //包含头文件
#define uchar unsigned char                            //宏定义
#define uint unsigned int                            //宏定义
#define LCD_data  P0                                 //数据口
sbit int0=P3^0;                                        //串口读入
sbit int1=P3^1;                                        //串口写出
sbit dxzk=P1^4;                                        //串口读/写转换开关
sbit LCD_RS  =  P1^0;            //数据/地址寄存器选择输入
sbit LCD_RW  =  P1^1;            //液晶读/写控制
sbit LCD_EN  =  P1^2;            //液晶使能控制
sbit LCD_PSB =  P2^7;            //串/并方式控制
sbit LCD_RST  =  P2^6;              //    lcd复位端
char a[13];                            //字符数组a,ID卡的十六进制卡号,a[13]为系统自动增设的终结符(\0)
char b[13];                            //字符数组b,要写入ID卡的十六进制卡号
         
         
         
         
 void main()
     {
        init();                                          //调用初始化子函数
        while(1)
            {   
                if(flag==1)   
                    {                                        //读取卡号
                        flag=0;                                //清除flag标志位
                          ES=0;                        //关串口中断
                        lcd_wcmd(0x01);              //清除LCD的显示内容
                        delay(5);                                       
                        if(dxzk=='1')                        //若串口读/写转换开关为高电平(向卡读卡号)
                            {                                                              
                                i=0;                        // i清零
                                lcd_pos(0,0);               //设置显示位置为第一行的第1个字符
                                while(a[i]!= '\0')
                                    {
                                        lcd_wdat(a[i]);        //逐个元素写卡号到显示屏
                                        i++    ;               
                                    }
                            }
                         else                                 //若串口读/写转换开关为低电平 (向卡写卡号   
                             {                                 
                                for ( i = 0; i < 13; i++)                    //将数组b[]的逐个元素写入ID卡中(即曼彻斯特内码)
                                    {
                                        SBUF=b[i];
                                        while(!TI);
                                        TI=0;
                                     }
                                                             //    将新写的卡号显示在显示屏上
                                 i=0;                        // i清零
                                 lcd_pos(1,0);               //设置显示位置为第二行的第1个字符
                                 while(b[i]!= '\0')
                                    {
                                        lcd_wdat(b[i]);        //逐个元素写卡号到显示屏   
                                        i++    ;               
                                    }
                            }
                     }
             }
    }
void ser() interrupt 4                                //串口中断程序
    {
        ES=0;                                        //关串口中断
        RI=0;                                        //清零串口接收标志位
        for ( i = 0; i < 13; i++)                    //在c语言中,数组是不能整体赋值的,即a[13]=SBUF是错误的,必须是逐个元素赋值才行
                                                            //读取卡号
                    {                                             
                        a[i] = SBUF;                        
                        while(!RI);
                        RI=0;
                    }
        flag=1;
        ES=1;                                        //开串口中断
    }   
搜索更多相关主题的帖子: 成功 串口 while 显示 i++ 
2017-10-19 17:38
快速回复:写卡程序,读的部分很成功,写的部分不成功,应该如何编程?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026395 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved