标签:output 分辨率 panel start 打开 计时 .com mat 命令
;(写) MOV P1,#05H MOV DPTR, #0AAAAH MOV A, #3FH MOVX @DPTR, A ;(读) MOV P1,#02H MOV DPTR, #0AAAAH MOVX A, @DPTR ;地址由P0,P1.0~2,P2共同决定
CONT: MOV DPTR, #0FEFFH ;数据指针指向口地址 MOVX A, @DPTR ;检测按键,向74LS244读入数据 MOVX @DPTR, A ;向74LS273输出数据,驱动LED SJMP CONT ;循环
MOV DPTR,@7F00H MOV A,#0C2H ;11000010,(打开了计时器A口为输入(0),B口为输出0,PC1:PC0 = 00(A/B基本输入输出,C口输入)) MOVX @DPTR,A MOV A,#0AAH MOV DPTR,#7E25H ;写入的是内存,地址是7E25H,刚好符合写入RAM的要求(81C55的RAM只有256B) MOVX @DPTR,A
#include <reg51.h> sbit encoder_selet=P2^7; sbit numeric_display=P2^6; unsigned char leddata[]={ 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07,0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x76, 0x38, 0x37, 0x3E, 0x73, 0x5C,0x40, 0x00, 0x00 }; unsigned char lower_key_set[4]={0x0e,0x0d,0x0b,0x07}; unsigned char lower_key_set_colum[4]={0xe0,0xd0,0xb0,0x70}; void delay(unsigned int); void scan_keyboard(int); void scan_keyboard_col(int); void display_key(int); static int pos= 0; int main(void) { int pos = 0; bstv51_init(); while(1) { scan_keyboard_col(0); scan_keyboard_col(1); scan_keyboard_col(2); scan_keyboard_col(3); } return 0; } void scan_keyboard(int line) { unsigned char in, lower_key,in_tmp; int selet_key; lower_key = lower_key_set[line]; P3 = lower_key|0xf0; in = P3; in_tmp= in & 0x0f; in &= 0xf0; in |= lower_key; if(in!= (lower_key|0xf0)) { delay(5); P3 = lower_key|0xf0; in = P3; in &= 0xf0; in |= lower_key; if(in != (lower_key|0xf0)) //软件防抖 { in_tmp = in & 0xf0; switch(in_tmp) //找到相应的坐标 { case 0xe0: selet_key= 0 + line*4; break; case 0xd0: selet_key= 1 + line*4; break; case 0xb0: selet_key= 2 + line*4; break; case 0x70: selet_key= 3 + line*4; break; } while(in != (lower_key|0xf0)) { in = P3; in &=(lower_key|0xf0); } display_key(selet_key); } } } void scan_keyboard_col(int colum) { unsigned char in, lower_key,in_tmp; int selet_key; lower_key = lower_key_set_colum[colum]; P3 = lower_key|0x0f; in = P3; in_tmp= in & 0x0f; in &= 0x0f; in |= lower_key; if(in!= (lower_key|0x0f)) { delay(5); P3 = lower_key|0x0f; in = P3; in &= 0x0f; in |= lower_key; if(in != (lower_key|0x0f)) //软件防抖 { in_tmp = in & 0x0f; switch(in_tmp) //找到相应的坐标 { case 0x0e: selet_key= 0 + colum*4; break; case 0x0d: selet_key= 1 + colum*4; break; case 0x0b: selet_key= 2 + colum*4; break; case 0x07: selet_key= 3 + colum*4; break; } while(in != (lower_key|0x0f)) { in = P3; in &=(lower_key|0x0f); } display_key(selet_key); } } } void display_key(int selet) { P0=0x00; //全部点亮 encoder_selet=1; encoder_selet=0; P0=leddata[selet]; numeric_display=1; numeric_display=0; } void delay(unsigned int xms) { unsigned int i,j; for(i=xms;i>0;i--) //i=xms即延时约xms毫秒 for(j=112;j>0;j--); }
ORG 0000H AJMP MAIN_START ORG 0100H MAIN_START: MOV R0,#30H ;设置x数据指针 MOV R1,#50H ;设置y数据指针 MOV R2,#0 ;清计数器为零 ;输出x数据到DAC0832 U2的输入寄存器 GOON: MOV DPTR,#0DFFFH ;x数据DAC地址为DFFFH MOV A, @R0 MOVX @DPTR,A ;写数据到DAC0832 U2 INC R0 ;x数据指针指向下一个数据 ;输出y数据到DAC0832 U2的输入寄存器 MOV DPTR,#0BFFFH ;y数据DAC地址为BFFFH MOV A,@R1 MOVX @DPTR,A ;写数据到DAC0832 U3 INC R1 ;y数据指针指向下一个数据 ;把所有DAC0832的输入数据寄存器的数据写入到DAC转换寄存器,;1μs后同时输出数据到绘图仪 MOV DPTR,#7FFFH ;DAC转换寄存器地址为7FFFH MOVX @DPTR,A ;使能和启动D/A转换 INC R2 ;统计输出数据个数 CJNE R2, #20,GOON ;输出20个数据后,绘图结束 SJMP $ ;停机 END
A、B、C:模拟通道地址选择信号,A为最低位,C为最高位。
SC:转换开始引脚,正脉冲有效。
EOC:转换结束标志信号,高电平有效,表示转换结束。在与处理器连接时,此引脚可以用来向处理器发出中断,或者是供处理器软件查询。
转换步骤:(直接看代码就好了)
第一步:地址信号到ABC;ALE地址锁存信号输出高电平,在ALE的上升沿,ADC0809锁存地址信息,选定通道;
第二步:模拟信号输入到ADC的模拟输入脚,使SC高电平,在一定的延时时间内,EOC变成低电平,表示转换开始;接着,外接处理器发出SC低电平信号,ADC0809开始在时钟信号的控制下,进行转换,经过tC时间后,转换完成,EOC输出高电平,并保持高电平,直到下次SC上升沿才变低。从SC变成高电平直到EOC输出电平的时间内,模拟输入信号的电压值必须保持不变。
第三步:处理器查询到EOC变高后,或者是在EOC申请中断后(所以一般要接外部中断),处理器控制OE信号,使其变高,ADC0809输出数据,数据线在OE下降沿到来后变成高阻态。在OE为低电平时,数据线一直保持为高阻态,因此ADC0809的数据线可以直接连接到系统数据总线上。
3. 单片机与ADC0809的两种连接方法:
;通道1的选择及启动转换 MOV DPTR, #8001H MOVX @DPTR, A ;此处A的值无关紧要
MOV DPTR, #8000H MOV A, #01H MOVX @DPTR,A;此处A的低3位为ADC0809的地址信号
ORG 0000H LJMP START ORG 0100H START: MOV DPTR, #07FFFH MOV A,#0 MOV R1,#0 OUTPUT_UP: MOVX @DPTR,A ADD A,#4 INC R1 NOP NOP NOP NOP CJNE R1,#51,OUTPUT_UP MOV A,#0 MOVX @DPTR,A LJMP START END
#include <reg51.h> #define SUM 4 typedef struct _PanelNumber { unsigned char digitalNum; unsigned char port; }PanelNumber; void delay(void); int main(void) { PanelNumber numberSet[SUM]={{0xF9,0x70}, //num:1 port:P2^7 {0xA4,0xb0}, //num:2 port:P2^6 {0xB0,0xd0}, //num:3 port:P2^5 {0x99,0xe0}}; //num:4 port:P2^4 int i; while(1) { for(i = 0;i!=SUM;i++) { P2 = 0xff; P2 = numberSet[i].port; P0 = numberSet[i].digitalNum; delay(); } } return 0; } void delay(void) { unsigned char i,j; for (i=0;i<30;i++) { for (j=0;j<170;j++); } }
1 #include <reg51.h> 2 #include "voltmeter.h" 3 4 static NumberPanel numberPanel[3]; 5 6 int main(void) 7 { 8 IT0 = 1;//failling edge trigger 9 EX0 = 1;//enable interrupt 0 10 EA = 1;//enable global interrupt 11 12 numberPanel[0].outputPort = 0xfbff; 13 numberPanel[1].outputPort = 0xfdff; 14 numberPanel[2].outputPort = 0xfeff; 15 16 START_ADC(adcAddress);//start adc transformation 17 18 while(1); 19 return 0; 20 } 21 22 void OnADCTransform_Completed() 23 interrupt INT0 using REGISTER_0 24 { 25 unsigned char result = 0; 26 float rResult; 27 28 READ_DATA(result,adcAddress); 29 30 rResult = (float)result * 0.0196078; 31 rResult *= 100; 32 33 translateResult((int)(rResult)); 34 35 START_ADC(adcAddress);//restart adc transformation 36 } 37 38 void translateResult(int result) 39 { 40 int dividend = 100,i = 2; 41 unsigned char number; 42 43 for(;dividend != 0; dividend /= 10, i--) 44 { 45 number = digitalNumberSet[result/ dividend]; 46 result %= dividend; 47 48 //open WD and output the data, 49 //the data will lock in the register while WD is low level 50 OUTPUT_DATA(i,number); 51 } 52 }
1 #define INT0 0 2 #define REGISTER_0 0 3 #define START_ADC(a) ((*a) = 0) 4 #define OUTPUT_DATA(i,data) ((*(numberPanel[i].outputPort)) = data) 5 #define READ_DATA(data,add) (data = (*add)) 6 7 //choose channel 0, while P2.7 is low level 8 unsigned char xdata *const adcAddress = 0x0ff8; 9 10 typedef struct _NumberPanel 11 { 12 unsigned char xdata *outputPort; 13 }NumberPanel; 14 15 unsigned char const digitalNumberSet[] 16 = {0xC0, 0xF9, 0xA4, 0xB0, 17 0x99, 0x92, 0x82, 0xF8, 18 0x00, 0x90, 0x88, 0x83, 19 0xC6, 0xA1, 0x86, 0x8E}; 20 21 void translateResult(unsigned char result);
标签:output 分辨率 panel start 打开 计时 .com mat 命令
原文地址:http://www.cnblogs.com/Philip-Tell-Truth/p/6266634.html