版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include #include #include /-/ 16-bit SFR Definitions for F35x/-sfr16 TMR2RL = 0xCA; / Timer2 reload valuesfr16 TMR2 = 0xCC; / Timer2 countersfr16 ADC0DEC = 0x9A; / ADC0 Decimation Ratio Register/sfr16 ADC0 = 0xbd;/-/ Global CONSTANTS/-#define SYSCLK / SYSCLK frequency in Hz#define MDCLK / Modulator
2、 clock in Hz (ideal is / (2.4576 MHz)#define OWR 960 / Desired Output Word Rate in Hz ADC0输出字速率,最大960#define BAUDRATE / Baud rate of UART in bps #define uchar unsigned char#define uint unsigned int#define DataPort P0sbit LCM_EN=P10;sbit LCM_RS=P11; unsigned char D1,D2,D3,D4,D5,D6,D7,D8;/sbit LED = P
3、07; unsigned int k;/-/ Function PROTOTYPES/-void Oscillator_Init (void);void Port_Init (void);void UART0_Init (void);void ADC0_Init(void);void delay(int i);void WriteCommandLCM(uchar CMD);void WriteDataLCM(uchar dataW);void InitLcd();void lcd_write_char(uchar x,uchar y,uchar dataW) ;/-/ MAIN Routine
4、/-void main (void) PCA0MD &= 0x40; / WDTE = 0 (clear watchdog timer / enable) Oscillator_Init(); / Initialize system clock Port_Init(); / Initialize Crossbar and GPIO / UART0_Init(); / Initialize UART0 for printfs InitLcd(); ADC0_Init(); / Initialize ADC0 AD0INT = 0; ADC0MD = 0x83; / Start continuou
5、s conversions EA = 1; / Enable global interrupts while (1) / Spin forever /-/ Initialization Subroutines/-void delay(int i) /大概0.43ms int j,k; for(j=0;ji;j+) for(k=0;k4; delay(5); LCM_EN=1; delay(10); LCM_EN=0; delay(10); /CMD=CMD4; DataPort&=0xf0; / delay(2); DataPort|=(CMD&0x0f); delay(10); LCM_EN
6、=1; delay(10); LCM_EN=0; void WriteDataLCM(uchar dataW) / delay(2); LCM_EN=0; LCM_RS=1;/ delay(2); DataPort&=0xf0;/ delay(2); DataPort|=(dataW&0xf0)4; delay(2); LCM_EN=1; delay(5); LCM_EN=0; delay(5); / dataW=dataW4; DataPort&=0xf0;/ delay(2); DataPort|=(dataW&0x0f); delay(2); LCM_EN=1; delay(5); LC
7、M_EN=0; void InitLcd() delay(2000); WriteCommandLCM(0x28); /4位数据总线 /delay(5); WriteCommandLCM(0x01); /清屏 WriteCommandLCM(0x0C); /显示开及光标设置 / WriteCommandLCM(0x0f); / delay(200); /-/ Oscillator_Init/-/ Return Value : None/ Parameters : None/ This routine initializes the system clock to use the interna
8、l 24.5MHz/ oscillator as its clock source. Also enables missing clock detector reset./-void Oscillator_Init (void) OSCICN = 0x83; / Configure internal oscillator for 配置内部振荡器 / its lowest frequency RSTSRC = 0x04; / Enable missing clock detector/-/ Port_Init/-/ Return Value : None/ Parameters : None/T
9、hisfunctioninitializestheGPIO and the Crossbar 初始化GPI0和交叉开关/ Pinout:/ P0.4 - UART TX (digital, push-pull) / P0.5 - UART RX (digital, open-drain)/ AIN0.2 - ADC0 input/-void Port_Init (void) / XBR0 = 0x01; / UART0 Selected XBR1 = 0x40; / Enable crossbar and weak pull-ups P0MDOUT |= 0xDf; / TX, LEDs =
10、Push-pull P1MDOUT |=0x03;/-/ UART0_Init/-/ Return Value : None/ Parameters : None/ Configure the UART0 using Timer1, for and 8-N-1./-/*void delay(unsigned int time) unsigned int i; while(-time) for(i=0;i125;i+); */*void UART0_Init (void) SCON0 = 0x10; / SCON0: 8-bit variable bit rate 串口控制寄存器 / level
11、 of STOP bit is ignored / RX enabled / ninth bits are zeros / clear RI0 and TI0 bits if (SYSCLK/BAUDRATE/2/256 1) TH1 = -(SYSCLK/BAUDRATE/2); CKCON |= 0x08; / T1M = 1; SCA1:0 = xx else if (SYSCLK/BAUDRATE/2/256 4) TH1 = -(SYSCLK/BAUDRATE/2/4); CKCON &= 0x0B; / T1M = 0; SCA1:0 = 01 CKCON |= 0x01; els
12、e if (SYSCLK/BAUDRATE/2/256 12) TH1 = -(SYSCLK/BAUDRATE/2/12); CKCON &= 0x0B; / T1M = 0; SCA1:0 = 00 else if (SYSCLK/BAUDRATE/2/256 48) TH1 = -(SYSCLK/BAUDRATE/2/48); CKCON &= 0x0B; / T1M = 0; SCA1:0 = 10 CKCON |= 0x02; else while (1); / Error. Unsupported baud rate TL1 = TH1; / Init Timer1 定时器1是用来确
13、定有相同的波特率 TMOD &= 0xf0; / TMOD: timer 1 in 8-bit autoreload TMOD |= 0x20; TR1 = 1; / START Timer1 TI0 = 1; / Indicate TX0 ready*/-/ ADC0_Init/-/ Return Value : None/ Parameters : None/ Initialize the ADC to use the temperature sensor. (non-differential)/-void ADC0_Init (void) REF0CN |= 0x03; / Enable
14、 internal Vref ADC0CN = 0x00; / Gain = 1, Unipolar mode 最后三位 PGA增益=1,ADC控制寄存器 ADC0CF = 0x00; / Interrupts upon SINC3 filter output ADC0配置寄存器,位4选择哪一个滤波器转换结束后使AD0INT中断标志置1, / and uses internal VREF 位2是VREF源选择位 ADC0CLK = (SYSCLK/MDCLK)-1; / Generate MDCLK for modulator. 调制器时钟分频系数,由最佳调制器时钟频率反求系数 / Ideal
15、ly MDCLK = 2.4576MHz / Program decimation rate for desired OWR ADC0DEC = (unsigned long) MDCLK / (unsigned long) OWR / / ADC0抽取比寄存器,确定ADC输出字速率,由输出字速率反求抽取比 (unsigned long) 128) - 1; ADC0BUF = 0x00; / Turn off Input Buffers ADC0MUX = 0x08; / Select AIN0.2 模拟多路选择控制寄存器 ADC0MD = 0x81; / Start internal ca
16、libration ADC0控制寄存器,校准和转换选择 while(AD0CALC != 1); / Wait until calibration is complete EIE1 |= 0x08; / Enable ADC0 Interrupts 转换结束中断允许 ADC0MD = 0x80; / Enable the ADC0 (IDLE Mode)/-/ Interrupt Service Routines/-/-/ ADC0_ISR/-/ This ISR prints the result to the UART. The ISR is called after each ADC/
17、conversion./-void ADC0_ISR (void) interrupt 10 unsigned long ADC_OutputVal; static double accumulator = 0; / unsigned long int i; static unsigned int measurements = 0; static unsigned int number=0; / static unsigned long average; static unsigned int flag = 1; unsigned int result=0; while(!AD0INT); AD0INT = 0; / InitLcd(); ADC_OutputVal=0x; ADC_OutputVal = ADC0H; ADC_OutputVal =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年度LED屏幕亮度调节与节能改造合同
- 2024年度知识产权保护合同:MLB棒球帽正品知识分享
- 2024年度物业服务合同标的及安全生产责任书
- 2024年多功能空调维修合作协议
- 2024装修合同该如何写范文
- 2024办公家具购买合同
- 2024年城市基础设施建设合同 with 工程质量与投资预算
- 2024年出版发行代理合同
- 【初中生物】脊椎动物(第2课时两栖动物和爬行动物) 2024-2025学年七年级生物上学期(人教版2024)
- 2024加工贸易合同
- GB/T 625-2024化学试剂硫酸
- 综合办公楼装修改造工程施工组织设计方案
- 三人直播带货协议书范文模板
- 北京邮电大学《云计算》2023-2024学年期末试卷
- 中央空调年度维保方案
- QCT1177-2022汽车空调用冷凝器
- 24春国家开放大学《学前儿童美术教育活动指导》期末大作业参考答案
- 数字化时代背景下教师角色的思考
- 和谐相处之道心理健康课件
- 医院应急演练:食物中毒
- 2021版特种设备目录
评论
0/150
提交评论