⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lprtpos.c

📁 原创一个简单打小票POS机源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
   #include <stdio.h>
   #include <absacc.h>
   #include <reg52.h>
   #include <math.h>
   #include <intrins.h>
   #define UINT8  unsigned char
   #define UINT16 unsigned int
   #define UINT32 unsigned long
/*        新增特殊功能寄存器定义        */  
sfr	 ISP_DATA	=   0xe2;
sfr     ISP_ADDRH	=   0xe3;  
sfr	 ISP_ADDRL	=   0xe4;
sfr	 ISP_CMD	=   0xe5; 
sfr	 ISP_TRIG	=   0xe6;   
sfr	 ISP_CONTR    =   0xe7; 

#define F_TM F0
#define TIMER0_ENABLE  TL0=TH0; TR0=1;
#define TIMER0_DISABLE TR0=0;
 sbit busy=P3^4;sbit BT_SND=P3^5;
 sbit BT_REC=P1^2;sbit p16=P1^6;


sbit sda = P3^2;
sbit scl = P3^3;
sbit p37 = P3^7;
sbit vp15=P1^5;
sbit vp20=P2^0;
sbit vp21=P2^1;
sbit vp22=P2^2;
sbit vp23=P2^3;
sbit vp24=P2^4;
idata UINT8 rom_snd[9];
idata UINT8 time[7];  
/*time[0]-sec time[1]--min time[2]-hour time[3]-day time[4]-week time[5]-month time[6]-year*/
  UINT8 code  led[27]={0xe7,0x84,0xd3,0xd6,0xb4,0x76,0x77,0xc4,0xf7,0xf4,0x08,
                       0xf5,0x37,0x63,0x97,0x73,0x71,0xf6,0xb5,0x23,0xe5,0xd9,
                       0x10,0x33,0x34,0x17,0xd9}; 

   UINT8 code keytab[4][12]=
{
{0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X0B,0XFF,0XFF,0XFF,0XFF,0XFF},
{0XFF,0X01,0X04,0X07,0X00,0X0D,0XFF,0X11,0X14,0X17,0X1A,0X1D},
{0XFF,0X02,0X05,0X08,0X0A,0X10,0XFF,0X12,0X15,0X18,0X1B,0X1E},
{0XFF,0X03,0X06,0X09,0X0C,0X0E,0XFF,0X13,0X16,0X19,0X1C,0X1F}
};
  bit flag=0,lcbj=0;
  UINT8 nmm=0,unit=0,pmbj,cred1=0,cred2=0;
  UINT8 data cyear=0x06,cmonth=0x08,cday=0x29,chour=15,cmin=30,dday;
// UINT8 idata dwmc[16],ypass[4];
 UINT8 idata  zdmoney[8],zmmoney[8],umoney1[8],umoney2[8],umoney3[8],umoney4[8],umoney5[8],umoney6[8];



void prtinit(void) ;


/*延时tms*/
void delay(UINT8 t)
{
UINT8 i,j;
for(i=0;i<t;i++){
for(j=0;j<112;j++)
{;}}
}
/*发送I2C总线起始条件子程序 */

char I_start()
{
scl=1; /* release SCL */
sda=1; /* release SDA */
_nop_();
if( scl==0 || sda==0 ) return 0; /* IIC bus not available, Start false */
else
{
scl=1; /* Send start operation */
_nop_();
_nop_();
sda=0; /* SDA high-to-low when SCL high */
_nop_();
_nop_();
_nop_(); /*one cycle delay function */
_nop_(); /*declare in <intrins.h> */
_nop_();
scl=0; 
_nop_();
sda=1; /*release SDA */
}
} /*return with SDA high, SCL low */

/*I2C总线停止条件子程序 */
void I_stop()
{ 
sda=0;
_nop_();
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
sda=1; /* SDA low-to-high when SCL high, return with SCL SDA high */
}

/*字节数据传送子程序*/
 

bit  sendbyte_p(UINT8 c)          //if  ACK=1 the data of sended  is ok
{                               //if  ACK=0 the data of sended  is not received
  UINT8 BitCnt;
 bit ACK;

 for(BitCnt=0;BitCnt<8;BitCnt++)     // data`length is eight
      {
        if((c<<BitCnt)&0x80)
    {
     sda=1;
       }
         else
    {
    sda=0;
          }
          _nop_();

      scl=1;                /*begin receive data*/
//_nop_();_nop_(); _nop_();
_nop_();_nop_();_nop_();
     scl=0;
               }

          _nop_();
          _nop_();
     sda=1;                /*begin receive ACK*/
      _nop_();
      _nop_();
     scl=1;
//_nop_();_nop_(); _nop_();
_nop_();_nop_();_nop_();

     if(sda==1)
  {
   ACK=0;        /*Is receive ACK?*/
      }
       else
     {
      ACK=1;
        }
     scl=0;
      _nop_();
      _nop_();
     return(ACK);

}


UINT8  rcvbyte_p(void)
{
   UINT8 retc;
   UINT8 BitCnt;

   retc=0;
   sda=1;              /*set receive`state*/
   for(BitCnt=0;BitCnt<8;BitCnt++)
        {
          _nop_();

          scl=0;          /*begin receive data*/

//_nop_();_nop_(); _nop_();
_nop_();_nop_();_nop_();

          scl=1;          /*make data valid*/
          _nop_();
          _nop_();
          retc=retc<<1;
          if(sda==1)retc=retc+1;
          _nop_();
          _nop_();
        }
   scl=0;
   _nop_();
   _nop_();

   return(retc);
}

 

void ack_i2c_p(bit a)
{

   if(a==0)
  {
   sda=0;        /*is not last byte*/
    }
        else
  {
   sda=1;     /*is last byte*/
         }
//_nop_();_nop_(); _nop_();
_nop_();_nop_();_nop_();

   scl=1;
//_nop_();_nop_(); _nop_();
_nop_();_nop_();_nop_();

  scl=0;                 /*begin receive data  again*/
     _nop_();
     _nop_();

}

void get_time(UINT8 time[])
{
     UINT8 i;
     bit a;
     a=0;

       I_start();
       while(~sendbyte_p(0xa2));               //send  slave  address
       while(~sendbyte_p(0x02));               //send word address
       I_start();
       while(~sendbyte_p(0xa3));
       for (i=0; i<7; i++)
          {
             time[i]=rcvbyte_p();
             if (i==6){
             a=1;
              }
             ack_i2c_p(a);
          }
       I_stop();

       time[0] &= 0x7f;
       time[1] &= 0x7f;
       time[2] &= 0x3f;
       time[3] &= 0x3f;
       time[4] &= 0x07;
       time[5] &= 0x1f;
       time[6] &= 0xff;
}

void get_time1(UINT8 time[])
{
     UINT8 i;
     bit a;
     a=0;

       I_start();
       while(~sendbyte_p(0xa2));               //send  slave  address
       while(~sendbyte_p(0x02));               //send word address
       I_start();
       while(~sendbyte_p(0xa3));
       for (i=0; i<3; i++)
          {
             time[i]=rcvbyte_p();
             if (i==2){
             a=1;
              }
             ack_i2c_p(a);
          }
       I_stop();

       time[0] &= 0x7f;
       time[1] &= 0x7f;
       time[2] &= 0x3f;
     /* time[3] &= 0x3f;
       time[4] &= 0x07;
       time[5] &= 0x1f;
       time[6] &= 0xff;
       */
}


void set_time(UINT8 time[])
{
     UINT8 i;
 I_start();
       while(~sendbyte_p(0xa2));
       while(~sendbyte_p(0x02));
     for(i=0;i<7;i++)
      {
         while(~sendbyte_p(time[i]));
      }
      I_stop();
}


 
 
 
 
/*时钟显示子程序 */
void leddisplay(void)
{

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;
P2=P2&0xe0;vp15=0;
P0=led[time[2] / 16];
p37=1;
vp20=1;
delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;
P2=P2&0xe0;vp15=0;
P0=led[ time[2] % 16];
p37=1;
vp21=1;
delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;
P2=P2&0xe0;vp15=0;
if ((nmm / 50)==0) {P0=0x08;} else {P0=0x00;}
p37=1;
vp21=1;
delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;
P2=P2&0xe0;vp15=0;
P0=led[ time[1] / 16];
p37=1;
vp22=1;
delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;
P2=P2&0xe0;vp15=0;
P0=led[ time[1] % 16];
p37=1;
vp23=1;
delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;
P2=P2&0xe0;vp15=0;
P0=0;
p37=1;
vp24=1;
delay(1); 

/*
p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;
P2=P2&0xe0;vp15=0;
P0=0;
p37=1;
vp15=1;
delay(1); 
*/
}
 
/*pad program*/
UINT8 kbscanR(void)
{
UINT8 jjz,row;
jjz=0;
P1=0x9f;
P2=P2&0x1f;
if ((P1&0x9f)!=0x9f) 
 {
   delay(3);
    if  ((P1&0x9f)!=0x9f) 
    {
  	     switch (P1&0x9f)
	     {
	     case 0x9e:  /* 1、2、3*/
	        jjz=1;break;
	     case 0x9d:  /*4、5、6*/
	        jjz=2;break;
	     case 0x9b:  /*7、8、9*/
	        jjz=3;break;
	     case 0x97:   /*0、A、B*/
	        jjz=4;break;
	     case 0x8f:   /*C、F、D*/
	        jjz=5;break;        
	     case 0x1f:   /*回车键*/       	        
	       jjz=6; lcbj=1; break;
             case 0x1e:    /*回车+1、2、3*/
  	      jjz=7;break;
             case 0x1d:     /*回车+4、5、6*/
 	      jjz=8;break;
            case 0x1b:      /*回车+7、8、9*/
	      jjz=9;break;
	    case 0x17:      /*回车+0、A、B*/
	      jjz=10;break;
	   case 0x0f:      /*回车+C、F、D*/ 
             jjz=11;break;	  
	     default :
	     jjz=0;break;  
	     }         
    }
 }
 
 return(jjz);  
     
}

UINT8 kbscanL(void)
{
UINT8 jjz,lin,dd;
jjz=0;

P2=P2|0xe0;
P1=P1&0x60;
if ((P2&0xe0)!=0xe0) 
 {
   delay(3);
    if ((P2&0xe0)!=0xe0) 
    {
	     switch (P2&0xe0)
	     {
	     case 0x60:       /*1、4、7、0、C*/
	        jjz=1;break;
	     case 0xa0:       /*2、5、8、A、F*/
	        jjz=2;break;
	     case 0xc0:      /*3、6、9、B、D*/
	        jjz=3;break;
	     default :
	     jjz=0;break;  
	     } 
    }
 }
 
 return(jjz);  
     
}

UINT8 kbscan(void)
{
   UINT8 jz,row,lin;
  row=kbscanR();
 lin=kbscanL();
  jz=keytab[lin][row]; 
  if (jz!=0xff) { flag=1;return(jz);}
  else return(0xff);
  
}

/*padprogram*/
void errshow(void)
{
p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0x73;vp21=1;p37=1;delay(1);

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff; 
p37=0;P2=P2&0xe0;vp15=0;P0=0xf5;vp22=1;p37=1;delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0xf5;vp23=1;p37=1;delay(1);

}
/*显示suc子程序*/
void setpassok(void)
{
p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0x76;vp21=1;p37=1;delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0xa7;vp22=1;p37=1;delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0x63;vp23=1;p37=1;delay(1); 

}


/*时钟设置*/

/*时钟设置显示子程序2006-09-28*/
void clockshow(UINT8 clockbj,clockH,clockL)
{
p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=clockbj;p37=1;vp20=1;delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0x10;vp21=1;p37=1;delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=clockH;vp22=1;p37=1;delay(1); 


p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=clockL;vp23=1;p37=1;delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0xf4;vp15=1;p37=1;delay(1); 

p37=0;P2=P2&0xe0;vp15=0;P0=0;p37=1;vp15=1;P2=0xff;
p37=0;P2=P2&0xe0;vp15=0;P0=0xf5;vp24=1;p37=1;delay(1); 


}


/*设置时钟子程序  0--year  1--month  2--day  3--week 4-- hour  5--min  

按BCD码格式存放的日期    2006-09-28*/
void  setclock(void)
{
 UINT8 rq[6],ncount,ecount;
 bit errbj,wbj;
 UINT8 i,pjz,scount,j;
 UINT8 rqbj,rqH,rqL;
 UINT16  yrq;
   
      P0=0;P2=P2&0xf6;P2=P2|0x09;
      scount=ncount=0;pjz=0xff;rqbj=0x00;rqH=rqL=26;
     for (i=0;i<6;i++) {rq[i]=0x00;}
	            
	    while (scount==0)  
	    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -