TM4C123GH6PM程序
模式一&模式二:单次计时&周期计时/*******************************************
开发坏境:CCSv5.4
开发板:TIVA C Launchpad(TM4C123GH6PM)
程序功能:16位定时器,单次定时模式和周期性定时模式
程序说明:
编程者:Linchpin
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//5分频,使用PLL,外部晶振16M,system时钟源选择 main osc。系统时钟40MHZ
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//使能GPIOF外设
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//使能TIMER0
//TimerConfigure(TIMER0_BASE, TIMER_CFG_ONE_SHOT);//单次计数模式
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);//周期性计数模式
TimerLoadSet(TIMER0_BASE, TIMER_A,SysCtlClockGet() / 10 - 1);//计数频率10HZ
IntEnable(INT_TIMER0A);//NVIC
//使能TIMER0A
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//TIMEOUT标志位触发中断
IntMasterEnable();
//master interrupt enable API for all interrupts
TimerEnable(TIMER0_BASE, TIMER_A);
//TIMER0A开始计数,当计数值等于TimerLoadSet,触发中断
while(1)
{
}
}
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//清除标志位
if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
}
else
{
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
}
}
模式三:计数捕获
/*******************************************
开发坏境:CCSv5.4
开发板:TIVA C Launchpad(TM4C123GH6PM)
程序功能:16位定时器,计数捕获模式,递增计数模式
程序说明:捕获引脚PB6,当捕获边沿数达到Match时产生中断
编程者:Linchpin
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//5分频,使用PLL,外部晶振16M,system时钟源选择 main osc。系统时钟40MHZ
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//使能TIMER0 32位(TIMER0A16位+TIMER0B16位)
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//使能GPIOF和GPIOC外设
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinConfigure(GPIO_PB6_T0CCP0); //#define GPIO_PC4_WT0CCP0 0x00021007
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
//计数捕获模式,上升沿捕获,Two half-width timers
TimerConfigure(TIMER0_BASE,TIMER_CFG_A_CAP_COUNT_UP|TIMER_CFG_SPLIT_PAIR);
//捕获模式,A定时器,上升沿捕获,增计数模式,到达匹配值后可自动清零
TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
IntEnable(INT_TIMER0A);
//使能TIMER0A
TimerIntEnable(TIMER0_BASE, TIMER_CAPA_MATCH);
//定时器A捕获事件触发中断
IntMasterEnable();
//master interrupt enable API for all interrupts
TimerEnable(TIMER0_BASE, TIMER_A);
//TIMER0A开始计数,当计数值等于TimerLoadSet,触发中断
while(1)
{
}
}
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE,TIMER_CAPA_MATCH);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 14);
SysCtlDelay(SysCtlClockGet() / 30);//100ms
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
}
模式四:计时捕获
/*******************************************
开发坏境:CCSv5.4
开发板:TIVA C Launchpad(TM4C123GH6PM)
程序功能:16位定时器,计时捕获模式
程序说明:捕获引脚PB6
编程者:Linchpin
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//5分频,使用PLL,外部晶振16M,system时钟源选择 main osc。系统时钟40MHZ
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
//使能TIMER0 32位(TIMER0A16位+TIMER0B16位)
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//使能GPIOF和GPIOC外设
GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
GPIOPinTypeGPIOInput(GPIO_PORTB_BASE, GPIO_PIN_6);
GPIOPinConfigure(GPIO_PB6_T0CCP0); //#define GPIO_PC4_WT0CCP0 0x00021007
GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_6);
TimerConfigure(TIMER0_BASE,TIMER_CFG_A_CAP_TIME_UP|TIMER_CFG_SPLIT_PAIR);//计时捕获模式,上升沿捕获
TimerControlEvent(TIMER0_BASE,TIMER_A,TIMER_EVENT_POS_EDGE);
//捕获模式,A定时器,上升沿捕获
IntEnable(INT_TIMER0A);
//使能TIMER0A
TimerIntEnable(TIMER0_BASE, TIMER_CAPA_EVENT);
//定时器A捕获事件触发中断
IntMasterEnable();
//master interrupt enable API for all interrupts
TimerEnable(TIMER0_BASE, TIMER_A);
//TIMER0A开始计数,当计数值等于TimerLoadSet,触发中断
while(1)
{
}
}
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE,TIMER_CAPA_EVENT);
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
SysCtlDelay(SysCtlClockGet() / 30);//100ms
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 14);
}
方式一:GPIO模拟SPI通信
/*******************************************
开发坏境:CCSv5.4
开发板:TIVA C Launchpad(TM4C123GH6PM)
程序功能:DAC_TLV5618 输出正弦波
程序说明:1.DIN——PC6 2.SCLK——PC5 3.CS——PC4 4.OUTA 5.AGND 6.REF 7.OUTB 8.VDD
编程者:Linchpin
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/fpu.h"
#include "driverlib/sysctl.h"
#include "grlib/grlib.h"
#include "driverlib/gpio.h"
#include "inc/hw_gpio.h"
#define uchar unsigned char
#define uint unsigned int
//void CS(uchar i);
//void SCLK(uchar i);
//void DIN(uchar i);
void init_DAC(void);
void DA_conver(uint temp);
void Write_A(float out_volt);
int VoltToData(float out_volt) ;
void delay_Nms(uint n);
float sinx_128[]={0.299734,0.313719,0.327637,0.341454,0.355137,0.368653,0.381968,0.395052,0.407873,0.420399,0.432601,0.444449,0.455914,0.466969,0.477588,0.487745,0.497414,0.506574,0.515202,0.523277,0.530779,0.537692,0.543997,0.549680,0.554727,0.559126,0.562866,0.565939,0.568336,0.570053,0.571084,0.571429,0.571084,0.570053,0.568336,0.565939,0.562866,0.559126,0.554727,0.549680,0.543997,0.537692,0.530780,0.523277,0.515202,0.506575,0.497415,0.487745,0.477589,0.466970,0.455915,0.444449,0.432601,0.420400,0.407873,0.395053,0.381969,0.368653,0.355138,0.341455,0.327638,0.313720,0.299734,0.285715,0.271696,0.257710,0.243792,0.229975,0.216292,0.202777,0.189461,0.176377,0.163556,0.151030,0.138829,0.126981,0.115515,0.104460,0.093841,0.083684,0.074015,0.064855,0.056227,0.048152,0.040649,0.033737,0.027432,0.021749,0.016702,0.012303,0.008563,0.005490,0.003093,0.001376,0.000344,0.000005,0.000344,0.001376,0.003092,0.005490,0.008562,0.012302,0.016701,0.021748,0.027431,0.033736,0.040648,0.048151,0.056226,0.064853,0.074013,0.083683,0.093839,0.104458,0.115513,0.126979,0.138827,0.151028,0.163554,0.176375,0.189459,0.202774,0.216290,0.229973,0.243790,0.257708,0.271693,0.285713,};
uint num;
void main(void)
{
//使能FPU
FPUEnable();
FPULazyStackingEnable();
SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_10MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);//使能GPIO外设
SysCtlGPIOAHBEnable(GPIO_PORTC_BASE);//挂在AHB高性能总线上
GPIOPinTypeGPIOOutput(GPIO_PORTC_BASE, GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6);
init_DAC();
while(1)
{
Write_A(sinx_128[num++]);
if(num>=128) num=0;
}
}
//片选信号端,低电平有效,PC4
/*void CS(uchar i)
{
if(i) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,GPIO_PIN_4);
else GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,~GPIO_PIN_4);
}
//同步串行时钟输入,PC5
void SCLK(uchar i)
{
if(i) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,GPIO_PIN_5 );
else GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,~GPIO_PIN_5);
}
//串行数据输入端,串行时钟上升沿输入,PC6
void DIN(uchar i)
{
if(i) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,GPIO_PIN_6 );
else GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,~GPIO_PIN_6);
}*/
/******初始化DAC***************/
void init_DAC(void)
{
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,GPIO_PIN_4);//CS(1);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,~GPIO_PIN_5);//SCLK(0);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,~GPIO_PIN_6);//DIN(0);
}
void DA_conver(uint temp)
{
uchar i;
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,~GPIO_PIN_4);//CS(0);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,GPIO_PIN_5 );//SCLK(1);
for(i=0;i<16;i++)
{
if( (temp & 0x8000) ==0) GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,~GPIO_PIN_6);
else GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_6,GPIO_PIN_6);
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,~GPIO_PIN_5 );
//;
temp<<=1;
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_5,GPIO_PIN_5 );
}
GPIOPinWrite(GPIO_PORTC_BASE, GPIO_PIN_4,GPIO_PIN_4);
}
void Write_A(float out_volt)
{
//int Data_A;
//Data_A=VoltToData(out_volt);
//A通道
DA_conver(0xc000|(0x0fff&VoltToData(out_volt)));
}
int VoltToData(float out_volt) //说明ref为参考源 out_volt为输出模拟电压值
{
int temp2;
temp2=(int)((out_volt*4096)/(2*3.3));
return(temp2&0xfff);
位数字量函数
方式二:硬件SPI通信(速度比GPIO模拟快很多)
/*******************************************
开发坏境:CCSv5.4
开发板:TIVA C Launchpad(TM4C123GH6PM)
程序功能:TLV5618 SPI通信(TI模式)
程序说明:1.DIN——PF1 2.SCLK——PF2 3.CS——PF3
DAC采样速率:95KHZ
编程者:Linchpin
********************************************/
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ssi.h"
#include "grlib/grlib.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/ssi.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#define uchar unsigned char
#define uint unsigned int
void DAC_Write_A(float out_volt);
void main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_10MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//SysCtlGPIOAHBEnable(GPIO_PORTF_BASE);//挂在AHB高性能总线上
GPIOPinConfigure(GPIO_PF2_SSI1CLK);
GPIOPinConfigure(GPIO_PF3_SSI1FSS);
GPIOPinConfigure(GPIO_PF1_SSI1TX);
GPIOPinTypeSSI(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_3|GPIO_PIN_2);
//SSIConfigSetExpClk(SSI1_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0 , SSI_MODE_MASTER, 25000000, 16);
SSIConfigSetExpClk(SSI1_BASE, SysCtlClockGet(), SSI_FRF_TI , SSI_MODE_MASTER, 25000000, 16);
SSIEnable(SSI1_BASE);
while(1)
{
DAC_Write_A(1);
//SysCtlDelay(SysCtlClockGet()/3000);
DAC_Write_A(2);
//SysCtlDelay(SysCtlClockGet()/3000);
}
}
void DAC_Write_A(float out_volt)
{
//(uint)(out_volt*4095)/(2*3.281) 先将电压值转化为0~4095的整数
位二进制数,后12位为数据位
位为1100(命令位):快速模式,正常功耗,写数据到A通道
SSIDataPut(SSI1_BASE, 0xc000|(0x0fff&((uint)((out_volt*4095)/(2*3.281)))));
while(SSIBusy(SSI1_BASE)) ;//等待发送完毕
}
TM4C123GH6PM程序的更多相关文章
- JavaScript之父Brendan Eich,Clojure 创建者Rich Hickey,Python创建者Van Rossum等编程大牛对程序员的职业建议
软件开发是现时很火的职业.据美国劳动局发布的一项统计数据显示,从2014年至2024年,美国就业市场对开发人员的需求量将增长17%,而这个增长率比起所有职业的平均需求量高出了7%.很多人年轻人会选择编 ...
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- 微信小程序开发心得
微信小程序也已出来有一段时间了,最近写了几款微信小程序项目,今天来说说感受. 首先开发一款微信小程序,最主要的就是针对于公司来运营的,因为,在申请appid(微信小程序ID号)时候,需要填写相关的公司 ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- 微信应用号(小程序)开发IDE配置(第一篇)
2016年9月22日凌晨,微信宣布“小程序”问世,当然只是开始内测了,微信公众平台对200个服务号发送了小程序内测邀请.那么什么是“小程序”呢,来看微信之父怎么说 看完之后,相信大家大概都有些明白了吧 ...
- 编写高质量代码:改善Java程序的151个建议(第5章:数组和集合___建议75~78)
建议75:集合中的元素必须做到compareTo和equals同步 实现了Comparable接口的元素就可以排序,compareTo方法是Comparable接口要求必须实现的,它与equals方法 ...
- 【探索】在 JavaScript 中使用 C 程序
JavaScript 是个灵活的脚本语言,能方便的处理业务逻辑.当需要传输通信时,我们大多选择 JSON 或 XML 格式. 但在数据长度非常苛刻的情况下,文本协议的效率就非常低了,这时不得不使用二进 ...
- 通过Jexus 部署 dotnetcore版本MusicStore 示例程序
ASPNET Music Store application 是一个展示最新的.NET 平台(包括.NET Core/Mono等)上使用MVC 和Entity Framework的示例程序,本文将展示 ...
- Code Review 程序员的寄望与哀伤
一个程序员,他写完了代码,在测试环境通过了测试,然后他把它发布到了线上生产环境,但很快就发现在生产环境上出了问题,有潜在的 bug. 事后分析,是生产环境的一些微妙差异,使得这种 bug 场景在线下测 ...
随机推荐
- 利用 SQL Monitor 查看语句运行状态步骤
利用 SQL Monitor 查看语句运行状态步骤 1.确定语句被 SQL Monitor 监控 SQL> SELECT * FROM GV$SQL_MONITOR WHERE sql_id=' ...
- jQuery UI 多选下拉框插件:jquery-ui-multiselect
前一个项目,由于项目需求,需要大量使用到下拉多选框,而由于本人又不会写有关 CSS 样式,所以,便上网找到了这个 jQuery 插件:jquery-ui-multiselect .该款插件提供了基本下 ...
- BZOJ 1051: [HAOI2006]受欢迎的牛 缩点
1051: [HAOI2006]受欢迎的牛 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/ ...
- iOS开发技巧系列---详解KVC(我告诉你KVC的一切)
KVC(Key-value coding)键值编码,单看这个名字可能不太好理解.其实翻译一下就很简单了,就是指iOS的开发中,可以允许开发者通过Key名直接访问对象的属性,或者给对象的属性赋值.而不需 ...
- ios开发——实用技术篇OC篇&iOS的主要框架
iOS的主要框架 阅读目录 Foundation框架为所有的应用程序提供基本系统服务 UIKit框架提供创建基于触摸用户界面的类 Core Data框架管着理应用程序数据模型 Core ...
- Haproxy图解
http://blog.csdn.net/tantexian/article/details/50056199
- php执行效率相关的语句
一:字符替换: strtr > str_replace > preg_replace 注意: 1:一般用strtr函数的这种形式:string strtr ( string $str , ...
- 如何用eclispe远程调试tomcat--转载
原文地址:http://jingyan.baidu.com/article/0320e2c1f4ef6b1b87507b06.html tomcat是一种非常常见的java web应用服务器,有时候服 ...
- Session fixation--wiki
http://en.wikipedia.org/wiki/Session_fixation In computer network security, session fixation attacks ...
- CentOS下通过locale来设置字符集
转载:http://www.centoscn.com/CentOS/config/2013/1013/1784.html 在Centos中通过locale来设置程序运行的不同语言环境,locale由A ...