Trích:
Nguyên văn bởi tdm
while(flag==1)
{
lay_font(mang);//
trong đây mình sẽ xử lý font như thế nào cho hợp lý vậy anh và cách lấy ký tự trong chuỗi nhận dc như thế nào anh(e đã nghĩ 3 ngày nay rồi vẫn ko tìm dc hướng giải quyết
}
|
sao em lấy vẫn không được vậy anh!!!!!!!!!!!!!!
anh xem e viet bi sai cho nao khong ạk?
#include <16f877a.h>
#device 16f877*=16 ADC=10
#include <stdlib.h>
#include <string.h>
#fuses nowdt,noprotect,nolvp,hs,put
#use delay(clock=20000000)
#use fast_io(b)
#use fast_io(c)
#use rs232(baud=9600,parity=n,xmit=pin_c6,rcv=pin_c7)
#byte porta=0x05
#byte portb=0x06
#byte portc=0x07
#bit b0=portb.0
#bit b1=portb.1
#bit b2=portb.2
#bit b3=portb.3
#bit b4=portb.4
#bit b5=portb.5
void doc_adc();
void lay_font(char * textptr);
unsigned char bi,temp,chieu_dai=0;
unsigned char hien_thi[64];
char string[5];
char string1[5];
char string2[5];
char string3[10];
const BYTE TEXT[51][5] ={0x00, 0x00, 0x00, 0x00, 0x00, // SPACE
0x00, 0x00, 0x5F, 0x00, 0x00, // !
0x00, 0x03, 0x00, 0x03, 0x00, // "
0x14, 0x3E, 0x14, 0x3E, 0x14, // #
0x24, 0x2A, 0x7F, 0x2A, 0x12, // $
0x43, 0x33, 0x08, 0x66, 0x61, // %
0x36, 0x49, 0x55, 0x22, 0x50, // &
0x00, 0x05, 0x03, 0x00, 0x00, // '
0x00, 0x1C, 0x22, 0x41, 0x00, // (
0x00, 0x41, 0x22, 0x1C, 0x00, // )
0x14, 0x08, 0x3E, 0x08, 0x14, // *
0x08, 0x08, 0x3E, 0x08, 0x08, // +
0x00, 0x50, 0x30, 0x00, 0x00, // ,
0x08, 0x08, 0x08, 0x08, 0x08, // -
0x00, 0x60, 0x60, 0x00, 0x00, // .
0x20, 0x10, 0x08, 0x04, 0x02, // /
0x3E, 0x51, 0x49, 0x45, 0x3E, // 0
0x04, 0x02, 0x7F, 0x00, 0x00, // 1
0x42, 0x61, 0x51, 0x49, 0x46, // 2
0x22, 0x41, 0x49, 0x49, 0x36, // 3
0x18, 0x14, 0x12, 0x7F, 0x10, // 4
0x27, 0x45, 0x45, 0x45, 0x39, // 5
0x3E, 0x49, 0x49, 0x49, 0x32, // 6
0x01, 0x01, 0x71, 0x09, 0x07, // 7
0x36, 0x49, 0x49, 0x49, 0x36, // 8
0x26, 0x49, 0x49, 0x49, 0x3E, // 9
0x00, 0x36, 0x36, 0x00, 0x00, // :
0x00, 0x56, 0x36, 0x00, 0x00, // ;
0x08, 0x14, 0x22, 0x41, 0x00, // <
0x14, 0x14, 0x14, 0x14, 0x14, // =
0x00, 0x41, 0x22, 0x14, 0x08, // >
0x02, 0x01, 0x51, 0x09, 0x06, // ?
0x3E, 0x41, 0x59, 0x55, 0x5E, // @
0x7E, 0x09, 0x09, 0x09, 0x7E, // A
0x7F, 0x49, 0x49, 0x49, 0x36, // B
0x3E, 0x41, 0x41, 0x41, 0x22, // C
0x7F, 0x41, 0x41, 0x41, 0x3E, // D
0x7F, 0x49, 0x49, 0x49, 0x41, // E
0x7F, 0x09, 0x09, 0x09, 0x01, // F
0x3E, 0x41, 0x41, 0x49, 0x3A, // G
0x7F, 0x08, 0x08, 0x08, 0x7F, // H
0x00, 0x41, 0x7F, 0x41, 0x00, // I
0x30, 0x40, 0x40, 0x40, 0x3F, // J
0x7F, 0x08, 0x14, 0x22, 0x41, // K
0x7F, 0x40, 0x40, 0x40, 0x40, // L
0x7F, 0x02, 0x0C, 0x02, 0x7F, // M
0x7F, 0x02, 0x04, 0x08, 0x7F, // N
0x3E, 0x41, 0x41, 0x41, 0x3E, // O
0x7F, 0x09, 0x09, 0x09, 0x06, // P
0x1E, 0x21, 0x21, 0x21, 0x5E, // Q
0x7F, 0x09, 0x09, 0x09, 0x76};// R
const BYTE TEXT2[44][5]={0x26, 0x49, 0x49, 0x49, 0x32, // S
0x01, 0x01, 0x7F, 0x01, 0x01, // T
0x3F, 0x40, 0x40, 0x40, 0x3F, // U
0x1F, 0x20, 0x40, 0x20, 0x1F, // V
0x7F, 0x20, 0x10, 0x20, 0x7F, // W
0x41, 0x22, 0x1C, 0x22, 0x41, // X
0x07, 0x08, 0x70, 0x08, 0x07, // Y
0x61, 0x51, 0x49, 0x45, 0x43, // Z
0x00, 0x7F, 0x41, 0x00, 0x00, // [
0x02, 0x04, 0x08, 0x10, 0x20, // \
0x00, 0x00, 0x41, 0x7F, 0x00, // ]
0x04, 0x02, 0x01, 0x02, 0x04, // ^
0x40, 0x40, 0x40, 0x40, 0x40, // _
0x00, 0x01, 0x02, 0x04, 0x00, // `
0x20, 0x54, 0x54, 0x54, 0x78, // a
0x7F, 0x44, 0x44, 0x44, 0x38, // b
0x38, 0x44, 0x44, 0x44, 0x44, // c
0x38, 0x44, 0x44, 0x44, 0x7F, // d
0x38, 0x54, 0x54, 0x54, 0x18, // e
0x04, 0x04, 0x7E, 0x05, 0x05, // f
0x08, 0x54, 0x54, 0x54, 0x3C, // g
0x7F, 0x08, 0x04, 0x04, 0x78, // h
0x00, 0x44, 0x7D, 0x40, 0x00, // i
0x20, 0x40, 0x44, 0x3D, 0x00, // j
0x7F, 0x10, 0x28, 0x44, 0x00, // k
0x00, 0x41, 0x7F, 0x40, 0x00, // l
0x7C, 0x04, 0x78, 0x04, 0x78, // m
0x7C, 0x08, 0x04, 0x04, 0x78, // n
0x38, 0x44, 0x44, 0x44, 0x38, // o
0x7C, 0x14, 0x14, 0x14, 0x08, // p
0x08, 0x14, 0x14, 0x14, 0x7C, // q
0x00, 0x7C, 0x08, 0x04, 0x04, // r
0x48, 0x54, 0x54, 0x54, 0x20, // s
0x04, 0x04, 0x3F, 0x44, 0x44, // t
0x3C, 0x40, 0x40, 0x20, 0x7C, // u
0x1C, 0x20, 0x40, 0x20, 0x1C, // v
0x3C, 0x40, 0x30, 0x40, 0x3C, // w
0x44, 0x28, 0x10, 0x28, 0x44, // x
0x0C, 0x50, 0x50, 0x50, 0x3C, // y
0x44, 0x64, 0x54, 0x4C, 0x44, // z
0x00, 0x08, 0x36, 0x41, 0x41, // {
0x00, 0x00, 0x7F, 0x00, 0x00, // |
0x41, 0x41, 0x36, 0x08, 0x00, // }
0x02, 0x01, 0x02, 0x04, 0x02};// ~
int8 i,m,t,flag,dem;
int8 n;
char mang[];
void dich(void);
void xuat(unsigned char bi);
void xoa_hien_thi();
#INT_RDA
void ngat()
{
mang[dem]=getc();
if(mang[dem]=='#')
{
flag=1;//co ngat
dem=0;
}
else
dem++;
while(flag==1)
{
lay_font(mang);
}
}
void main()
{int x=0;
int dv,chuc,tram;
enable_interrupts(int_rda);
enable_interrupts(global);
set_tris_b(0b00000000);
set_tris_d(0b00000000);
set_tris_a(0b000001);
doc_adc();
while(1)
{
doc_adc();
x=read_adc();
x=x/2.049;
dv=x%10;
chuc=(x%100)/10;
tram=x/100;
itoa(dv,10,string);//gan dv vao string
itoa(chuc,10,string1);//gan chuc vao string1
strcat(string1,string);//ket hop string1 va string hien thi la string1
itoa(tram,10,string2);//gan tram vao string2
strcat(string2,string1);//ghepstring1 va string2 hien thi string2
strcpy(string3,"nhiet do ");
strcat(string3,string2);
xoa_hien_thi();//xóa vùng nho hien thi truoc khi cap nhat nhiet do
lay_font(string3); // Write character set to matrix
b1=1;
b0=1;
b2=1;
b0=0;
b2=0;
for(m=0;m<=63;m++)
{
n=hien_thi[m];
n=~n;
xuat(n);
delay_us(1000);
dich();
}
}
}
void doc_adc()
{
setup_ADC(ADC_clock_internal);
setup_ADC_ports(AN0);
set_ADC_channel(0);
delay_us(1000);
}
void dich()
{
b1=0;
b0=1;
b0=0;
b2=1;
b2=0;
}
void xuat(unsigned char temp)
{
#bit flag_bit = temp.7
b4=0;
for(i=0;i<=7;i++)
{
if(flag_bit==1)
{b4=1;}
else
{b4=0;}
b3=1;
b3=0;
temp<<=1;
}
b5=1;
b5=0;
}
void lay_font(char * textptr)
{
int i, j;//
BYTE pixelData[5]; // Stores character data
for(i=0; textptr[i] != '\0'; ++i ) // Loop through the passed string
{
if(textptr[i] == '#')//textptr khai bao vi tri con tro
break;
if(textptr[i] < 'S') //ky tu nam o mang text
memcpy(pixelData, TEXT[textptr[i]-' '], 5);//copy 5 byte gia tri text[textptr[i]-'' vao pixeldata
else if(textptr[i] <= '~') // ky tu nam o mang text2
memcpy(pixelData, TEXT2[textptr[i]-'S'], 5);//copy 5 byte gia tri text2[textptr[i]-'s' vao pixeldata
else
memcpy(pixelData, TEXT[0], 5); // khoang trang
for(j=0;j<=4;j++)
{
hien_thi[chieu_dai]=(pixelData[j]);//hien thi tung ky tu
chieu_dai++;
}
}
}
void xoa_hien_thi(void)
{
chieu_dai=0;
for(m=0;m<=63;m++)
{
hien_thi[m]=0x00;//
}
}
phía dưới là code vb6 em viết đấy ạk anh xem dùmm e lun nha
Private Sub truyen_Click()
Dim data As String
data = Text1.Text
MSComm1.Output = "*"
MSComm1.Output = data
MSComm1.Output = "#"
End Sub
Private Sub exit_Click()
MsgBox "thoat"
End
End Sub
Private Sub Form_Load()
'cai dat thong so cho cong com...." COMFIG FOR COM PORT "
With MSComm1
.CommPort = 2 'cong COM 2
.Settings = "9600,N,8,1" 'Baudrate=9600,Ko KT chan le,frame 8 bit,1 bit stop
.InBufferSize = 1024 'Bo dem 1024 byte thi day
.InputLen = 0 'Doc toan bo gia tri bo dem
.RThreshold = 1 'Cho phep ngat khi su kien Receiver o MSCOMM
.SThreshold = 0 'Ko cho phep ngat khi su kien Send o MMSCOMM
.OutBufferSize = 512
.InputMode = comInputModeText
.PortOpen = True 'Mo cong COM
End With
End Sub