📄 ean.c
字号:
/******************************************
LPC2103 Advanced4 EAN
********************************************/
#include "config.h"
#include "LCD_Dis.h"
#include "Uart.h"
const unsigned char daoru[9]={0x00,0x0b,0x0d,0x13,0x19,0x1c,0x15,0x16,0x1a}; //coder : 0:A 1:B XXX XXX
// 1 2 3 4 5 6 7 8 9
// 0 1 2 3 4 5 6 7 8 9
const unsigned char a_coder[10] ={0x0d,0x19,0x13,0x3e,0x23,0x31,0x2f,0x3b,0x37,0x0b};
const unsigned char b_coder[10] ={0x27,0x33,0x1b,0x21,0x1e,0x39,0x05,0x11,0x09,0x17};
const unsigned char c_coder[10] ={0x72,0x66,0x6c,0x42,0x5c,0x4e,0x50,0x44,0x48,0x74};
unsigned char ean_code[13]={0};
/******************************************************
function: PaintBars
*****************************************************/
void PaintBars(DOTBYTE x,DOTBYTE y,DOTBYTE h)
{
uint8 i,j,flag;
SetPaintMode(0,0xff00);
h+=y;
Line(x,y,x++,h+5); // 1
Line(x,y,x++,h+5);
x++; // 0
x++;
Line(x,y,x++,h+5); // 1
Line(x,y,x++,h+5);
for(i=1;i<7;i++)
{
flag=0x40;
for(j=0;j<7;j++)
{
if(ean_code[i] & flag)
{
Line(x,y,x,h);
Line(x+1,y,x+1,h);
}
x+=2;
flag>>=1;
}
}
x++; // 0
x++;
Line(x,y,x++,h+5); // 1
Line(x,y,x++,h+5);
x++; // 0
x++;
Line(x,y,x++,h+5); // 1
Line(x,y,x++,h+5);
x++; // 0
x++;
for(i=7;i<13;i++)
{
flag=0x40;
for(j=0;j<7;j++)
{
if(ean_code[i] & flag)
{
Line(x,y,x,h);
Line(x+1,y,x+1,h);
}
x+=2;
flag>>=1;
}
}
Line(x,y,x++,h+5); // 1
Line(x,y,x++,h+5);
x++; // 0
x++;
Line(x,y,x++,h+5); // 1
Line(x,y,x++,h+5);
}
/*******************************************************
function: get Bar data
********************************************************/
void Ean(uint8 *pointer) //pointer a array[13]
{
uint8 i,flag;
uint8 lead;
uint16 check;
//////////check data
for(i=0;i<13;i++)
{
if(*(pointer+i)>9) return 'a'; //error exist no numbers.
}
if(*pointer==0) return 'a';
//////////data check over
lead=daoru[(*pointer++)-1]; //get coder method
ean_code[0]=lead;
flag=0x20;
for(i=1;i<12;i++) // left code of ean
{
if(i<7)
{
if(lead & flag)
ean_code[i]=b_coder[*(pointer++)];
else
ean_code[i]=a_coder[*(pointer++)];
flag=flag >> 1;
}
else
{
ean_code[i]=c_coder[*(pointer++)];
}
}
////////calculate check code
check=0;
pointer-=12;
for(i=0;i<12;i++)
{
if(i%2==0)
check+=*(pointer++);
else
check+=(uint16)((*(pointer++))*3);
}
i=(unsigned char)(10-check%10);
if(i!=*pointer) return 'b';
///////check over///////////
ean_code[12]=c_coder[*pointer];
PaintBars(20,100,70);
return 0;
}
//////////////////end function////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -