七段顯示器二位
程式碼
//於七段顯示器顯示二位數計數 #include "reg51.h" sbit x1=P3^0; sbit x2=P1^0; int a=2000,k=0; //0.5秒=2000*250us int b,c; unsigned char font[61] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10, 0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20, 0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30, 0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40, 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50, 0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x60}; char seg[6]={0x01,0x4f,0x12,0x06,0x4c,0x24}; int d, bcd[2]; unsigned char i; main() { TMOD = 0x03; TH0 = (256-250); TL0 = (256-250); TR0 = 1; //啟動計時器 IE = 0x82; //啟動Timer0中斷 bcd[0]=P1/10; bcd[1]=P1%10; d=bcd[0]*10+bcd[1]; x1=1; while(1); } void scan_7seg() interrupt 1 //Timer0中斷程式(中斷向量1) { if (--a==0) { a=2000; if (x1==0) //控制用 { P0=seg[k++]; } P2 = font[d--]; if (d==0) while(1); } }
文章標籤
全站熱搜
留言列表