Mình có nghiên cứu viết code và mô phỏng protuels khi không có mạch công suất là ULN2803 và transistor thì mạch chạy tốt, nhưng sau khi thêm công suất vào thì mạch bị nhiễu. mong mọi người giúp đỡ mình tìm hiểu là code sai chỗ nào. Do code mình viết còn nhiều sai sót và thuật toán chưa triệt để, mong mọi người góp ý thêm cho mình. Mình suy đoán là bị lỗi ở phần chốt dữ liệu ra con 595. Mình quét hàng, và đưa dữ liệu ra 595. Dùng phương pháp offscreen (cái này cũng chưa chắc chắn do code còn gà, dùng khá khá vòng lăp). Tính làm để tết lắp cho vui mà chắc không thành công rùi. Mong mọi người góp ý nhiều nhiều để mình có thể học hỏi được nhiều điều. Có gì code không hiểu mình sẽ giải thích. tks mọi người (mình có gửi flie mô phỏng và code: test2)
Code:
#include <16f877a.h> #fuses hs,nowdt,noprotect,nowrt #device *=16 #use delay(clock=20000000) #use fast_io(b) #use fast_io(c) #use fast_io(d) //////////////////////////////////////////////////////////////////////////////// typedef struct { int8 a[6];} table; const table font[]={ 0xff,0xff,0xff,0xff,0xff,0xff,// space 0 0xff,0xff,0xa0,0xff,0xff,0xff,// ! 1 0xff,0xff,0xf8,0xf4,0xff,0xff,// ' 2 0xeb,0x80,0xeb,0x80,0xeb,0xff,// # 3 0xdb,0xd5,0x80,0xd5,0xed,0xff,// $ 4 0xd8,0xea,0x94,0xab,0x8d,0xff,// % 5 0xc9,0xb6,0xa9,0xdf,0xaf,0xff,// & 6 0xff,0xff,0xf8,0xf4,0xff,0xff,// ' 7 0xff,0xe3,0xdd,0xbe,0xff,0xff,// ( 8 0xff,0xbe,0xdd,0xe3,0xff,0xff,// ) 9 0xd5,0xe3,0x80,0xe3,0xd5,0xff,// * 10 0xf7,0xf7,0xc1,0xf7,0xf7,0xff,// + 11 0xff,0xa7,0xc7,0xff,0xff,0xff,// , 12 0xf7,0xf7,0xf7,0xf7,0xf7,0xff,// - 13 0xff,0x9f,0x9f,0xff,0xff,0xff,// x 14 0xff,0xc9,0xc9,0xff,0xff,0xff,// / 15 0xc1,0xae,0xb6,0xba,0xc1,0xff,// 0 16 0xff,0xbd,0x80,0xbf,0xff,0xff,// 1 17 0x8d,0xb6,0xb6,0xb6,0xb9,0xff,// 2 18 0xdd,0xbe,0xb6,0xb6,0xc9,0xff,// 3 19 0xe7,0xeb,0xed,0x80,0xef,0xff,// 4 20 0xd8,0xba,0xba,0xba,0xc6,0xff,// 5 21 0xc3,0xb5,0xb6,0xb6,0xcf,0xff,// 6 22 0xfe,0x8e,0xf6,0xfa,0xfc,0xff,// 7 23 0xc9,0xb6,0xb6,0xb6,0xc9,0xff,// 8 24 0xf9,0xb6,0xb6,0xd6,0xe1,0xff,// 9 25 0xff,0xc9,0xc9,0xff,0xff,0xff,// : 26 0xff,0xa4,0xc4,0xff,0xff,0xff,// // 27 0xf7,0xeb,0xdd,0xbe,0xff,0xff,// < 28 0xeb,0xeb,0xeb,0xeb,0xeb,0xff,// = 29 0xff,0xbe,0xdd,0xeb,0xf7,0xff,// > 30 0xfd,0xfe,0xae,0xf6,0xf9,0xff,// ? 31 0xcd,0xb6,0x8e,0xbe,0xc1,0xff,// @ 32 0x83,0xf5,0xf6,0xf5,0x83,0xff,// A 33 0xbe,0x80,0xb6,0xb6,0xc9,0xff,// B 34 0xc1,0xbe,0xbe,0xbe,0xdd,0xff,// C 35 0xbe,0x80,0xbe,0xbe,0xc1,0xff,// D 36 0x80,0xb6,0xb6,0xb6,0xbe,0xff,// E 37 0x80,0xf6,0xf6,0xfe,0xfe,0xff,// F 38 0xc1,0xbe,0xb6,0xb6,0xc5,0xff,// G 39 0x80,0xf7,0xf7,0xf7,0x80,0xff,// H 40 0xff,0xbe,0x80,0xbe,0xff,0xff,// I 41 0xdf,0xbf,0xbe,0xc0,0xfe,0xff,// J 42 0x80,0xf7,0xeb,0xdd,0xbe,0xff,// K 43 0x80,0xbf,0xbf,0xbf,0xff,0xff,// L 44 0x80,0xfd,0xf3,0xfd,0x80,0xff,// M 45 0x80,0xfd,0xfb,0xf7,0x80,0xff,// N 46 0xc1,0xbe,0xbe,0xbe,0xc1,0xff,// O 47 0x80,0xf6,0xf6,0xf6,0xf9,0xff,// P 48 0xc1,0xbe,0xae,0xde,0xa1,0xff,// Q 49 0x80,0xf6,0xe6,0xd6,0xb9,0xff,// R 50 0xd9,0xb6,0xb6,0xb6,0xcd,0xff,// S 51 0xfe,0xfe,0x80,0xfe,0xfe,0xff,// T 52 0xc0,0xbf,0xbf,0xbf,0xc0,0xff,// U 53 0xe0,0xdf,0xbf,0xdf,0xe0,0xff,// V 54 0xc0,0xbf,0xcf,0xbf,0xc0,0xff,// W 55 0x9c,0xeb,0xf7,0xeb,0x9c,0xff,// X 56 0xfc,0xfb,0x87,0xfb,0xfc,0xff,// Y 57 0x9e,0xae,0xb6,0xba,0xbc,0xff,// Z 58 0xff,0x80,0xbe,0xbe,0xff,0xff,// [ 59 0xfd,0xfb,0xf7,0xef,0xdf,0xff,// \ 60 0xff,0xbe,0xbe,0x80,0xff,0xff,// ] 61 0xfb,0xfd,0xfe,0xfd,0xfb,0xff,// ^ 92 0x7f,0x7f,0x7f,0x7f,0x7f,0xff,// _ 63 0xff,0xff,0xf8,0xf4,0xff,0xff,// ' 64 0xdf,0xab,0xab,0xab,0xc7,0xff,// a 65 0x80,0xc7,0xbb,0xbb,0xc7,0xff,// b 66 0xff,0xc7,0xbb,0xbb,0xbb,0xff,// c 67 0xc7,0xbb,0xbb,0xc7,0x80,0xff,// d 68 0xc7,0xab,0xab,0xab,0xf7,0xff,// e 69 0xf7,0x81,0xf6,0xf6,0xfd,0xff,// f 70 0xf7,0xab,0xab,0xab,0xc3,0xff,// g 71 0x80,0xf7,0xfb,0xfb,0x87,0xff,// h 72 0xff,0xbb,0x82,0xbf,0xff,0xff,// i 73 0xdf,0xbf,0xbb,0xc2,0xff,0xff,// j 74 0xff,0x80,0xef,0xd7,0xbb,0xff,// k 75 0xff,0xbe,0x80,0xbf,0xff,0xff,// l 76 0x83,0xfb,0x87,0xfb,0x87,0xff,// m 77 0x83,0xf7,0xfb,0xfb,0x87,0xff,// n 78 0xc7,0xbb,0xbb,0xbb,0xc7,0xff,// o 79 0x83,0xeb,0xeb,0xeb,0xf7,0xff,// p 80 0xf7,0xeb,0xeb,0xeb,0x83,0xff,// q 81 0x83,0xf7,0xfb,0xfb,0xf7,0xff,// r 82 0xb7,0xab,0xab,0xab,0xdb,0xff,// s 83 0xff,0xfb,0xc0,0xbb,0xbb,0xff,// t 84 0xc3,0xbf,0xbf,0xdf,0x83,0xff,// u 85 0xe3,0xdf,0xbf,0xdf,0xe3,0xff,// v 86 0xc3,0xbf,0xcf,0xbf,0xc3,0xff,// w 87 0xbb,0xd7,0xef,0xd7,0xbb,0xff,// x 88 0xf3,0xaf,0xaf,0xaf,0xc3,0xff,// y 89 0xbb,0x9b,0xab,0xb3,0xbb,0xff,// z 90 0xfb,0xe1,0xe0,0xe1,0xfb,0xff,// ^ 62 0xe3,0xe3,0xc1,0xe3,0xf7,0xff,// -> 93 0xf7,0xe3,0xc1,0xe3,0xe3,0xff,// <- 94 0xef,0xc3,0x83,0xc3,0xef,0xff,// 95 0xff,0xff,0xff,0xff,0xff,0xff // blank char 96 }; //////////////////////////////////////////////////////////////////////////////// unsigned char string[]="CHUC MUNG NAM MOI-*-XUAN GIAP NGO-*-2014-*-AN KHANG THINH VUONG-*-VAN SU NHU Y-*-"; int1 value; int16 p,i,j,k,x,r,s; int16 m=0,length=0; int8 mang[33],mang1[4],mang2[7]; int8 loop[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //////////////////////////////////////////////////////////////////////////////// void kich_thuoc_chuoi() { while (string[length]!='\0') length++; } //////////////////////////////////////////////////////////////////////////////// void tao_mang_ki_tu() { for (i=k;i<=5;i++) { mang[m]=font[string[mang2[0]]-32].a[i]; m++; } for (j=1;j<=4;j++) { for (i=0;i<=5;i++) { mang[m]=font[string[mang2[j]]-32].a[i]; m++; } } if (k<=3) { for (i=0;i<=2+k;i++) { mang[m]=font[string[mang2[5]]-32].a[i]; m++; } } else { for (i=0;i<=5;i++) { mang[m]=font[string[mang2[5]]-32].a[i]; m++; } for (i=0;i<(k-3);i++) { mang[m]=font[string[mang2[6]]-32].a[i]; m++; } } } //////////////////////////////////////////////////////////////////////////////// void dich_32bit() { for (x=0;x<=7;x++) { mang1[0]=mang[x]; mang1[1]=mang[x+8]; mang1[2]=mang[x+16]; mang1[3]=mang[x+24]; for (i=0;i<=3;i++) { for (j=0;j<=7;j++) { value=~bit_test(mang1[3-i],j); output_bit(pin_b1,value); output_high(pin_b0); delay_cycles(3); output_low(pin_b0); } output_high(pin_b2); delay_cycles(3); output_low(pin_b2); } output_d(loop[7-x]); delay_ms(1); output_d(0); } } //////////////////////////////////////////////////////////////////////////////// void main() { set_tris_b(0); set_tris_c(0); set_tris_d(0); output_b(0); output_c(0); output_d(0); kich_thuoc_chuoi(); while (1) { for (r=1;r<=length;r++) { for (s=0;s<=6;s++) { if ((s+r)<length) mang2[s]=s+r; else mang2[s]=s+r-length; } for (k=0;k<=5;k++) { m=0; tao_mang_ki_tu(); for (p=0;p<=5;p++) { dich_32bit(); } } } } }
Comment