1、intrins.hvoid Delay1us(unsigned char us) while (us) _nop_(); -us; void SYSCLK_Init (void) int i; / delay counter OSCXCN = 0x67; / start external oscillator with / 18.432MHz crystal for (i=0; i 256; i+) ; / Wait for osc. to start up while (!(OSCXCN & 0x80) ; / Wait for crystal osc. to settle OSCICN =
2、 0x88; / select external oscillator as SYSCLK / source and enable missing clock / detector / OSCICN = 0x07; file:/interal 16MHZ #define PRT0CF P0MDOUT #define PRT1CF P1MDOUT #define PRT2CF P2MDOUT void PORT_Init (void) XBR0 = 0x07; / Enable SMBus, SPI0, and UART0 XBR1 = 0x00; XBR2 = 0x44; / Enable c
3、rossbar and weak pull-ups EMI0CF = 0x27; EMI0TC = 0x21; P74OUT = 0xFF; P0MDOUT = 0x15; P1MDOUT |= 0x3C; /P1.2-P1.5推挽输出 P1 &= 0xc3; /P1.2-P1.5=0 void SPI0_Init (void) SPI0CFG = 0x07; / data sampled on 1st SCK rising edge / 8-bit data words SPI0CFG|=0xC0; /CKPOL =1; SPI0CN = 0x03; / Master mode; SPI e
4、nabled; flags / cleared SPI0CKR = SYSCLK/2/8000000-1; / SPI clock 8; / set Timer0 to overflow in 1ms TL0 = -SYSCLK/1000; TR0 = 1; / START Timer0 IE|= 0x2;void Timer0_ISR (void) interrupt 1 /1ms if (Count1ms) Count1ms-;void Delay1ms(unsigned char T) Count1ms=T; while (Count1ms);void Delay1s(unsigned
5、char T) while (T) Delay1ms(200); T-;char GetKeyValue(void);void init_adc(void);unsigned int GetADCValue(char No);void TestLCD(void);void DispLCD(char *DispBuf,char num);void InitLCD(void); /初始化LCD void ShowWenDu(void);void Test7279(bit LoopFlag) ;void main (void) unsigned int w; char No,i,buf5; No=1
6、; WDTCN = 0xde; WDTCN = 0xad; /关看门狗 SYSCLK_Init (); / 初始化时钟Timer0_Init();/初始化定时器 PORT_Init (); /初始化IO口 SPI0_Init (); /初始化SPI0 init_adc(); CPT1CN|=0x80; /使能比较器1 REF0CN = 0x07; /使能片内参考电压 DAC0CN |= 0x80; /使能DAC0 DAC0H=0; DAC0L=0; EA=1; /开中断/Test7279(0); loop: Test7279(0) ;/关闭数码关显示 TestLCD(); InitLCD();
7、 No=0;/w = GetADCValue(1); for (;) i=GetKeyValue(); if (i=0)&(i=3) No=i; switch(No) case 1: ShowWenDu();break; case 2: ShowDianYa(); case 3: ShowYaLi(); case 0:goto loop; default: break; w = GetADCValue(No); Delay1ms(30); buf0=(w%10000)/1000; buf1=(w%1000)/100; buf2= buf3=(w%100)/10; buf4=(w%10); Di
8、spLCD(buf,1); showdu(); DispLCD(buf,2); showfu(); DispLCD(buf,3); showniu();模数转换c8051F020.h/* 压力应变片ADC实验*/ #define MUX_TEMP 0x08 #define MUX_VOLT 0x01 #define MUX_PRESS 0x02 unsigned int idata Temp, Press, Volt;unsigned char idata mux_select;sfr16 ADC0 = 0xbe; / ADC0 data void init_adc(void) ADC0CN
9、= 0x81; / ADC0 enabled; normal tracking / mode; ADC0 conversions are initiated / on write to AD0BUSY; ADC0 data is / left-justified / enable temp sensor, on-chip VREF, / and VREF output buffer mux_select = MUX_TEMP; / CPU on-chip temp sensor AMX0SL = MUX_TEMP; ADC0CF = (SYSCLK/2500000) 3; / ADC conv
10、ersion clock = 2.5MHz /ADC0CF |= 0x01; / PGA gain = 2 EIE2 &= 0x02; / disable ADC0 EOC interrupt EIE1 &= 0x04; / disable ADC0 window compare interrupt / On-chip temperature / AN1. 电位片/ AN2. 应变片void read_analog_inputs(void) long temp_long; AD0INT = 0; / clear conversion complete indicator AD0BUSY = 1
11、; / initiate conversion while (AD0INT = 0); / wait for conversion complete switch (mux_select) case MUX_TEMP: temp_long = ADC0 - 42380/2; temp_long = (temp_long * 200L) / 156; Temp=temp_long; AMX0SL = MUX_VOLT; / Select AIN1 for next read mux_select = MUX_VOLT; case MUX_VOLT: temp_long = ADC0; Volt
12、= 24*temp_long/655; AMX0SL = MUX_PRESS; / Select on-chip temp sensor mux_select = MUX_PRESS; case MUX_PRESS: temp_long = 24*temp_long/655; Press = temp_long;unsigned int GetADCValue(char No) read_analog_inputs(); switch (No) return Temp; return Volt; if (Press10) Press=0; return Press;C8051F020.h液晶点
13、阵显示实验-128*64,控制器KS0108实验准备:将拨码开关S1和S2置ON运行此程序将上下左右滚动显示“姓名,马彩霞学号,3100601033班级,通信1002”出现菜单,按键选择。#define LCD_DATA P2 #define LCD_RS P30 #define LCD_RW P31 #define LCD_E P32 #define LCD_CS1 P34 #define LCD_CS2 P33 #define LCD_RST P35 void Delay1ms(unsigned char);#define SELECTCS 0char code zero= /0/0x00
14、,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00, ;char code one= /1/0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00, char code two= /2/0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00, char code three= /3/0x00
15、,0x30,0x08,0x88,0x88,0x48,0x30,0x00,0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00, char code four= /4/0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00, char code five= /5/0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00, char code six= /6/0x00,
16、0xE0,0x10,0x88,0x88,0x18,0x00,0x00,0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00, char code seven= /7/0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, char code eight= /8/0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00, char code nine= /9/0x0
17、0,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00, char code mao= /:/0x00,0x00,0x00,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00, char code dot= /./0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00, char code wen= /温/0x10,0
18、x21,0x86,0x70,0x00,0x7E,0x4A,0x4A,0x4A,0x4A,0x4A,0x7E,0x00,0x00,0x00,0x00, 0x02,0xFE,0x01,0x40,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x41,0x41,0x7F,0x40,0x00, char code du= /度/0x00,0x00,0xFC,0x04,0x24,0x24,0xFC,0xA5,0xA6,0xA4,0xFC,0x24,0x24,0x24,0x04,0x00, 0x80,0x60,0x1F,0x80,0x80,0x42,0x46,0x2A,0x12,0
19、x12,0x2A,0x26,0x42,0xC0,0x40,0x00, char code dian= /电/0x00,0x00,0xF8,0x48,0x48,0x48,0x48,0xFF,0x48,0x48,0x48,0x48,0xF8,0x00,0x00,0x00, 0x00,0x00,0x0F,0x04,0x04,0x04,0x04,0x3F,0x44,0x44,0x44,0x44,0x4F,0x40,0x70,0x00, char code ya= /压/0x00,0x00,0xFE,0x02,0x42,0x42,0x42,0x42,0xFA,0x42,0x42,0x42,0x62,0x
20、42,0x02,0x00, 0x20,0x18,0x27,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x21,0x2E,0x24,0x20,0x20,0x00, char code li= /力/0x00,0x10,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0xF0,0x00,0x00, 0x00,0x00,0x80,0x40,0x20,0x18,0x06,0x01,0x00,0x00,0x40,0x80,0x40,0x3F,0x00,0x00, char code C= /C/0xC7,0x35,
21、0x0F,0x08,0x08,0x08,0x38,0x00,0x07,0x18,0x20,0x20,0x20,0x10,0x08,0x00, char code N= /牛顿/0x08,0xF8,0x30,0xC0,0x00,0x08,0xF8,0x08,0x20,0x3F,0x20,0x00,0x07,0x18,0x3F,0x00, char code m= /m/0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F, ;char code V= /V/0x08,0x78,0x88,0x
22、00,0x00,0xC8,0x38,0x08,0x00,0x00,0x07,0x38,0x0E,0x01,0x00,0x00, ;charcodescreen1= 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0x80,0x80,0x00,0x80,0xC0,0x80,0x80,0x80,0x00,0x00,0x00,0xC0,0x00,0x00,0x80,0x80,0x80,0xC0,0x80,0x0
23、0,0x00,0x00,0x00,0x40,0x80,0x40,0x80,0x00,0x00,0xC0,0x00,0x00,0x00,0xC0,0x40,0x40,0xC0,0x80,0x80,0x80,0xC0,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0
24、0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x000x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0xFC,0x80,0x40,0x04,0x04,0x040xFF,0x04,0x04,0x04,0x00,0x82,0x81,0xBE,0xEB,0xAA,0xAB,0xAA,0xEA,0xBF,0x80,0x80,0x00,0x61,0x19,0xFF,0x09,0x91,0x7F,0x00,0
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1