Commit 4807648c authored by FineL's avatar FineL 😛

10.24初步代码

parent 6329cde0
#ifndef __ADC_H__
#define __ADC_H__
#define SAMPLE_RATE 50000 // ADC0ת»»ËÙÂÊ
#define SAR0_CLK 4000000 // ADC0ʱÖÓƵÂÊ 2MHz 2000000
#define BIT0 (0x01)
#define BIT1 (0x02)
#define BIT2 (0x04)
#define BIT3 (0x08)
#define BIT4 (0x10)
#define BIT5 (0x20)
#define BIT6 (0x40)
#define BIT7 (0x80)
#define RT_flag 1
#define VREF0 2.4
void ADC0_Init(void);
void ADC0_Enable();
void ADC0_Disable();
void Timer3_Init(unsigned int counts);
void Timer3_Init2(unsigned int counts);
void ADC0_INT_ISR(void);
void Timer3_INT_ISR(void);
extern unsigned int ADC0_Value;
extern unsigned int Voltage[1500];
extern unsigned char Wait_flag;
#endif
#ifndef __DAC_H__
#define __DAC_H__
void DAC0_Init (void);
#endif
\ No newline at end of file
#ifndef __DATATYPE_H__
#define __DATATYPE_H__
#define INT8U unsigned char
#define INT8S char
#define INT16U unsigned int
#define INT16S int
#define INT32U unsigned long
#define INT32S long
#define BIT(x) (0x01 << (x))
#define BIT0 (0x01)
#define BIT1 (0x02)
#define BIT2 (0x04)
#define BIT3 (0x08)
#define BIT4 (0x10)
#define BIT5 (0x20)
#define BIT6 (0x40)
#define BIT7 (0x80)
#define accuracy (10000) //设置浮点数据精度,小数点4位
#endif
\ No newline at end of file
#ifndef __DEVICE_H__
#define __DEVICE_H__
void Device_Init ();
#endif
\ No newline at end of file
#ifndef __LCD_H__
#define __LCD_H__
void DrawSelect(unsigned char row,unsigned char col);
void Delayms(unsigned int ms);
void WrateC(unsigned char com);
void WrateD(unsigned char dat);
void LCDWrite(unsigned char type,unsigned char dat);
void LCD_Init();
void LCD_setXY(unsigned char X, unsigned char Y);
void LCD_DrawPoint(unsigned char x,unsigned char y);
void LCD_Clear();
void ClearLine(char row);
void LCD_Drawchar(unsigned char C,unsigned char row,unsigned char col);
void LCD_DrawcharS(unsigned char *C,unsigned char row,unsigned char col);
#endif
\ No newline at end of file
This diff is collapsed.
#ifndef __KEY_H__
#define __KEY_H__
// void KeyPort_Init (); //初始化键盘端口
unsigned char KeyScan (); //键盘扫描函数
#endif
\ No newline at end of file
This diff is collapsed.
"..\Src\ADC.c" LARGE OPTIMIZE (8,SPEED) BROWSE INCDIR(..\Inc;..\Src;..\Project) DEBUG OBJECTEXTEND PRINT(.\ADC.lst) TABS (2) OBJECT(.\ADC.obj)
\ No newline at end of file
<html>
<body>
<pre>
<h1>Vision Build Log</h1>
<h2>Tool Versions:</h2>
IDE-Version: Vision V5.31.0.0
Copyright (C) 2020 ARM Ltd and ARM Germany GmbH. All rights reserved.
License Information: L L, HP Inc., LIC=14RJ7-ENQ83-83VMD-86AVS-E8BHN-K6FAM
Tool Versions:
Toolchain: PK51 Prof. Developers Kit Version: 9.56.0.0
Toolchain Path: D:\Tool\Keil4_MDK\C51\BIN
C Compiler: C51.exe V9.56.0.0
Assembler: A51.exe V8.2.5.0
Linker/Locator: BL51.exe V6.22
Library Manager: LIB51.exe V4.30.1.0
Hex Converter: OH51.exe V2.7.0.0
CPU DLL: S8051.DLL V3.106.0.0
Dialog DLL: DCYG.DLL V2.74.0.0
Target DLL: SiC8051F.dll V3.8.0.0
Dialog DLL: TCYG.DLL V2.71.0.0
<h2>Project:</h2>
C:\Users\L\Desktop\08-C8051F020\Final version\Project\ADC.uvproj
Project File Date: 10/17/2023
<h2>Output:</h2>
Build target 'ADC'
linking...
Program Size: data=12.0 xdata=3040 code=5432
creating hex file from "ADC"...
"ADC" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:00
</pre>
</body>
</html>
This diff is collapsed.
".\TheMain.obj",
".\ADC.obj",
".\LCD.obj",
".\DAC.obj",
".\Device.obj",
".\Font.obj",
".\key.obj"
TO "ADC"
RAMSIZE(256)
DISABLEWARNING (16)
C51 COMPILER V9.56.0.0 ADC 10/18/2023 09:58:24 PAGE 1
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE ADC
OBJECT MODULE PLACED IN .\ADC.obj
COMPILER INVOKED BY: D:\Tool\Keil4_MDK\C51\BIN\C51.EXE ..\Src\ADC.c LARGE OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Inc;..\Src;
-..\Project) DEBUG OBJECTEXTEND PRINT(.\ADC.lst) TABS(2) OBJECT(.\ADC.obj)
line level source
1 #include "c8051f020.h"
2 #include "ADC.h"
3 #include "LCD.h"
4
5 extern unsigned long SYSCLK;
6 extern unsigned int Voltage[1500];
7
8 unsigned int ADC0_Value;
9 unsigned int datanum = 0;
10 unsigned int datanum2 = 0;
11
12 /**
13 * ADC0初始化
14 */
15 void ADC0_Init(void)
16 {
17 1 AMX0CF = 0; //配置AIN1单通道输入
18 1 AMX0SL = 1;
19 1
20 1 ADC0CF = ((SYSCLK/SAR0_CLK - 1) << 3); //设置ADC转换时钟
21 1 ADC0CF &= ~(BIT2 + BIT1 + BIT0); //PGA增益为1
22 1
23 1 ADC0CN &= ~(BIT6 + BIT5 + BIT3 + BIT1 + BIT0); //当ADC被使能时,除了转换期间之外一直处于跟踪方式
24 1 //清零转换结束标志 清零窗口比较中断标志 数据右对齐
25 1 ADC0CN |= BIT2; //定时器3溢出启动ADC0转换
26 1
27 1 REF0CN &= ~BIT4; //参考电压取自VREF0
28 1 REF0CN |= BIT1 + BIT0; //
29 1
30 1 EIE2 |= BIT1; //允许ADC转换结束中断
31 1 EA = 1;
32 1
33 1 ADC0CN |= BIT7; //使能ADC0
34 1 }
35
36 /**
37 * 关闭ADC0
38 */
39 void ADC0_Disable()
40 {
41 1 ADC0CN &= ~BIT7; //关闭ADC0
42 1 }
43
44 /**
45 * 打开ADC0
46 */
47 void ADC0_Enable()
48 {
49 1 ADC0CN |= BIT7; //使能ADC0
50 1 }
51
52 /**
53 * 初始化定时器3
54 * counts: 表示定时器需要计数的时钟个数
C51 COMPILER V9.56.0.0 ADC 10/18/2023 09:58:24 PAGE 2
55 */
56 void Timer3_Init(unsigned int counts)
57 {
58 1 TMR3CN &= ~(BIT7 + BIT2 + BIT0); //清零定时器3溢出标志 暂时关闭定时器3 定时器3时钟由T3M定义
59 1 TMR3CN &= ~BIT1; //定时器3时钟为系统时钟/12
60 1 TMR3RLL = ((65536 - counts) & 0xff);
61 1 TMR3RLH = (((65536 - counts) >> 8) & 0xff); //计算定时器3重载寄存器值
62 1 // TMR3RLL = 0xA0;
63 1 // TMR3RLH = 0xFF;
64 1 TMR3L = TMR3RLL;
65 1 TMR3H = TMR3RLH; //设定计数初值
66 1 EIE2 &= ~BIT0; //close
67 1 EA = 1;
68 1 TMR3CN |= BIT2; //启动定时器3
69 1 }
70
71 void Timer3_Init2(unsigned int counts)
72 {
73 1 TMR3CN &= ~(BIT7 + BIT2 + BIT0); //清零定时器3溢出标志 暂时关闭定时器3 定时器3时钟由T3M定义
74 1 TMR3CN |= BIT1; //定时器3时钟为系统时钟
75 1 TMR3RLL = ((65536 - counts) & 0xff);
76 1 TMR3RLH = (((65536 - counts) >> 8) & 0xff); //计算定时器3重载寄存器值
77 1 // TMR3RLL = 0xA0;
78 1 // TMR3RLH = 0xFF;
79 1 TMR3L = TMR3RLL;
80 1 TMR3H = TMR3RLH; //设定计数初值
81 1 EIE2 |= BIT0; //open
82 1 EA = 1;
83 1 TMR3CN |= BIT2; //启动定时器3
84 1 }
85
86 /**
87 * ADC0转换结束中断入口程序
88 */
89 void ADC0_INT_ISR(void) interrupt 15
90 {
91 1 if(AD0INT == 1)
92 1 {
93 2 if( RT_flag == 1 ) //Real-time storage and real-time dis
-play
94 2 {
95 3 if(datanum <= 127&& Wait_flag == 0)
96 3 {
97 4 Voltage[datanum] = (ADC0H << 8) + ADC0L;
98 4 datanum++;
99 4 }
100 3 else if (datanum >127)
101 3 {
102 4 Wait_flag = 1;
103 4 datanum = 0;
104 4 }
105 3 DAC0L = ADC0L;
106 3 DAC0H = ADC0H;
107 3 }
108 2 else //Single storage, continuous and stable display
109 2 {
110 3 if(datanum <= 1500)
111 3 {
112 4 Voltage[datanum] = (ADC0H << 8) + ADC0L;
113 4 if(Voltage[datanum] != Voltage[datanum-1]) datanum++;
114 4 }
115 3 }
C51 COMPILER V9.56.0.0 ADC 10/18/2023 09:58:24 PAGE 3
116 2 }
117 1 }
118
119 void Timer3_INT_ISR(void) interrupt 14
120 {
121 1 if(TMR3CN & BIT7)
122 1 {
123 2 TMR3CN &= ~BIT7;
124 2 DAC0L = Voltage[datanum2] & 0xFF;
125 2 DAC0H = (Voltage[datanum2] >> 8) & 0xFF;
126 2 datanum2++;
127 2 if(datanum2 >= 1500) datanum2 = 0;
128 2 }
129 1 }
*** WARNING C294 IN LINE 110 OF ..\Src\ADC.c: unreachable code
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 484 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 6 4
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
This diff is collapsed.
C51 COMPILER V9.56.0.0 DAC 10/17/2023 23:10:42 PAGE 1
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE DAC
OBJECT MODULE PLACED IN .\DAC.obj
COMPILER INVOKED BY: D:\Tool\Keil4_MDK\C51\BIN\C51.EXE ..\Src\DAC.c LARGE OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Inc;..\Src;
-..\Project) DEBUG OBJECTEXTEND PRINT(.\DAC.lst) TABS(2) OBJECT(.\DAC.obj)
line level source
1 //-----------------------------------------------------------------------------
2 // 1) Download the code to an C8051F020 Development Board
3 // 2) Ensure that pins 1 and 2 on the J22 header on the development board
4 // are shorted together. This connects VREF to decoupling capacitors.
5 // 3) Connect two oscillscope probes to pins DAC0 and DAC1. These pins are
6 // available on both the J11 (pins 3 and 4 respectively) and J20 headers
7 // (pin 3 and 4 respectively).
8 // 4) Confirm that there are two waveforms with the output of DAC1 leading
9 // the output DAC0 by 90 degrees. The frequency of both waveforms should
10 // be close to frequency defined by <FREQUENCY>
11 //-----------------------------------------------------------------------------
12 #include <c8051f020.h>
13 sfr16 RCAP4 = 0xE4; // Timer4 capture/reload
14 sfr16 TMR4 = 0xF4; // Timer4
15 sfr16 DAC0 = 0xd2; // DAC0 data
16 sfr16 DAC1 = 0xd5; // DAC1 data
17 //-----------------------------------------------------------------------------
18 // Global Constants
19 //-----------------------------------------------------------------------------
20 //#define SYSCLK 22118400 // Internal oscillator frequency in Hz
21 #define SAMPLE_RATE_DAC 100000L // DAC sampling rate in Hz
22 #define PHASE_PRECISION 65536 // range of phase accumulator
23 #define FREQUENCY 1000 // Frequency of output waveform in Hz
-
24 // <PHASE_ADD> is the change in phase between DAC samples; It is used in
25 // the set_DACs routine.
26 //-----------------------------------------------------------------------------
27 // Function Prototypes
28 //-----------------------------------------------------------------------------
29
30 void DAC0_Init(void)
31 {
32 1 DAC0CN = 0x80; // Enable DAC0 in left-justified mode
33 1 // managed by Timer4 overflows
34 1
35 1 // REF0CN |= 0x03; // Enable the internal VREF (2.4v) and
36 1 // the Bias Generator
37 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 4 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
"..\Src\Device.c" LARGE OPTIMIZE (8,SPEED) BROWSE INCDIR(..\Inc;..\Src;..\Project) DEBUG OBJECTEXTEND PRINT(.\Device.lst) TABS (2) OBJECT(.\Device.obj)
\ No newline at end of file
C51 COMPILER V9.56.0.0 DEVICE 10/17/2023 23:10:43 PAGE 1
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE DEVICE
OBJECT MODULE PLACED IN .\Device.obj
COMPILER INVOKED BY: D:\Tool\Keil4_MDK\C51\BIN\C51.EXE ..\Src\Device.c LARGE OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Inc;..\S
-rc;..\Project) DEBUG OBJECTEXTEND PRINT(.\Device.lst) TABS(2) OBJECT(.\Device.obj)
line level source
1 #include "C8051F020.h"
2 #include "datatype.h"
3
4 void Init_IO_Port ()
5 {
6 1 XBR2 |= BIT6; //使能交叉开关
7 1 }
8
9 void OSC_Init ()
10 {
11 1 INT16U i;
12 1 OSCICN |= BIT2 + BIT0 + BIT1; //设置内部时钟为16 MHz, 使能时钟丢失检测
13 1 OSCICN &= ~BIT3;
14 1 OSCICN |= BIT7;
15 1
16 1 //使用外部晶振
17 1 OSCXCN = 0x67; // Enable external crystal osc.
18 1 for (i=0; i < 1000; i++); // Wait at least 1ms
19 1 while (!(OSCXCN & BIT7)); // Wait for crystal osc to settle
20 1
21 1 OSCICN |= BIT3; // Select external clock source
22 1 OSCICN &= ~BIT2; // Disable the internal osc.
23 1 }
24
25 void Close_WDT ()
26 {
27 1 WDTCN = 0xde; // 关闭看门狗
28 1 WDTCN = 0xad;
29 1 }
30
31 void Device_Init ()
32 {
33 1 Close_WDT ();
34 1 OSC_Init ();
35 1 Init_IO_Port ();
36 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 58 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
"..\Src\Font.c" LARGE OPTIMIZE (8,SPEED) BROWSE INCDIR(..\Inc;..\Src;..\Project) DEBUG OBJECTEXTEND PRINT(.\Font.lst) TABS (2) OBJECT(.\Font.obj)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
C51 COMPILER V9.56.0.0 THEMAIN 10/18/2023 10:20:59 PAGE 1
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE THEMAIN
OBJECT MODULE PLACED IN .\TheMain.obj
COMPILER INVOKED BY: D:\Tool\Keil4_MDK\C51\BIN\C51.EXE ..\Src\TheMain.c LARGE OPTIMIZE(8,SPEED) BROWSE INCDIR(..\Inc;..\
-Src;..\Project) DEBUG OBJECTEXTEND PRINT(.\TheMain.lst) TABS(2) OBJECT(.\TheMain.obj)
line level source
1 #include "c8051f020.h"
2 #include "DataType.h"
3 #include "Device.h"
4 #include "string.h"
5 #include "stdio.h"
6 #include "ADC.h"
7 #include "LCD.h"
8 #include "DAC.h"
9 #include "key.h"
10 //100,1K,10K,100K
11
12 unsigned long SYSCLK = 12000000; // ⲿʱ 12MHz
13 unsigned int Voltage[1500];
14 unsigned char Wait_flag = 0;
15 unsigned char key=0;
16
17 void Show(void)
18 {
19 1 int i = 0;
20 1 if( RT_flag == 1)
21 1 {
22 2 while(1)
23 2 {
24 3 key = KeyScan();
25 3 if(key != 0)
26 3 {
27 4 switch(key)
28 4 {
29 5 case 1: Timer3_Init(10000);break;
30 5 case 2: Timer3_Init(1000);break;
31 5 case 3: Timer3_Init(100);break;
32 5 case 4: Timer3_Init(10);break;
33 5 }
34 4 }
35 3 while(!Wait_flag);
36 3 for(i=1;i<127;i++)
37 3 {
38 4 LCD_DrawPoint(i, Voltage[i]*0.01875);//Voltage/2/4096*2.4*64
39 4 }
40 3 LCD_Clear();
41 3 Wait_flag = 0;
42 3 }
43 2 }
44 1 else
45 1 {
46 2 while(!Voltage[1500]);
47 2 ADC0_Disable();
48 2 Timer3_Init2(175);
49 2 while(1)
50 2 {
51 3 for(i=0;i<127;i++)
52 3 {
53 4 LCD_DrawPoint(i, Voltage[i]*0.01875);
54 4 }
C51 COMPILER V9.56.0.0 THEMAIN 10/18/2023 10:20:59 PAGE 2
55 3 }
56 2 }
57 1 }
58
59 void main ()
60 {
61 1 Device_Init();
62 1 DAC0_Init ();
63 1 ADC0_Init ();
64 1 Timer3_Init(10);
65 1 LCD_Init();
66 1 LCD_Clear();
67 1 Show();
68 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 194 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 3006 2
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
This diff is collapsed.
"..\Src\key.c" LARGE OPTIMIZE (8,SPEED) BROWSE INCDIR(..\Inc;..\Src;..\Project) DEBUG OBJECTEXTEND PRINT(.\key.lst) TABS (2) OBJECT(.\key.obj)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment