簡易信號發生器 1啟用定時器中斷,從微控制器引腳輸出占空比為x%, x kHz的方波。 其中x為你的學號后2位,當后兩位為00時,可使用學號倒數4-3位 2 同時在液晶上按如下格式顯示: 3 簡易信號發生器 4定時器m,引腳n 5Fre=x,Duty=x 6你的姓名
注:在本目錄存放整個工程項目,包括源文件、頭文件、說明等
單片機源程序如下:
- #include <stdint.h>
- #include <stdbool.h>
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include "inc/hw_memmap.h"
- #include "inc/hw_types.h"
- #include "inc/hw_timer.h"
- #include "inc/hw_ints.h"
- #include "inc/hw_gpio.h"
- #include "inc/hw_i2c.h"
- #include "inc/hw_sysctl.h"
- #include "driverlib/timer.h"
- #include "driverlib/interrupt.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/systick.h"
- #include "driverlib/gpio.h"
- #include "driverlib/pin_map.h"
- #include "driverlib/ssi.h"
- #include "driverlib/i2c.h"
- #include "driverlib/udma.h"
- #include "driverlib/fpu.h"
- #include "driverlib/rom.h"
- #include "uc1701.h"
- //*****************************************************************************
- //Attention
- //TM4C123 NMI unlock - To those who want to use PF0 and PD7, be reminded that these pins defaults as NMI ! ! !
- //
- //*****************************************************************************
- //*****************************************************************************
- //
- // The error routine that is called if the driver library encounters an error.
- //
- //*****************************************************************************
- #ifdef DEBUG
- void
- __error__(char *pcFilename, unsigned long ulLine)
- {
- }
- #endif
- //*****************************************************************************
- //
- // Global variables
- //
- //
- //
- //*****************************************************************************
- unsigned char flag;
- unsigned int i;
- //*****************************************************************************
- //
- // The interrupt application.
- // Timer interrupt
- //
- //
- //*****************************************************************************
- void Timer0IntHandler(void)
- {
- // Clear the timer interrupt
- TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
- if(i<7)
- GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 1<<4); // 綠LED燈:亮;
-
- else
- GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_4, 0<<4); // 綠LED燈:亮
-
- i=i+1;
- if(i==60)
- i=0;
-
- }
- //*****************************************************************************
- char HZ[]={
- 0x08,0x04,0xC3,0x12,0x26,0x8A,0xA2,0xAA,0xA4,0xA3,0x22,0x26,0xEA,0x02,0x02,0x00,
- 0x00,0x00,0xFF,0x00,0x00,0x3F,0x24,0x24,0x24,0x3F,0x00,0x80,0xFF,0x00,0x00,0x00,/*"簡",0*/
- 0x00,0x00,0x00,0x00,0x7F,0xC9,0x49,0x49,0x49,0x49,0x49,0x7F,0x00,0x00,0x00,0x00,
- 0x00,0x08,0x04,0x42,0x23,0x12,0x8E,0x42,0x32,0x0E,0x42,0x82,0x42,0x3E,0x00,0x00,/*"易",1*/
- 0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00,
- 0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00,/*"信",2*/
- 0x80,0x80,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x80,0x80,0x00,
- 0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x44,0x84,0x44,0x3C,0x00,0x00,0x00,0x00,/*"號",3*/
- 0x00,0x00,0x18,0x16,0x10,0xD0,0xB8,0x97,0x90,0x90,0x90,0x92,0x94,0x10,0x00,0x00,
- 0x00,0x20,0x10,0x8C,0x83,0x80,0x41,0x46,0x28,0x10,0x28,0x44,0x43,0x80,0x80,0x00,/*"發",4*/
- 0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
- 0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00,/*"生",5*/
- 0x80,0x80,0x9E,0x92,0x92,0x92,0x9E,0xE0,0x80,0x9E,0xB2,0xD2,0x92,0x9E,0x80,0x00,
- 0x08,0x08,0xF4,0x94,0x92,0x92,0xF1,0x00,0x01,0xF2,0x92,0x94,0x94,0xF8,0x08,0x00,/*"器",6*/
- };
- char HZ1[]={
- 0x10,0x0C,0x44,0x44,0x44,0x44,0x45,0xC6,0x44,0x44,0x44,0x44,0x44,0x14,0x0C,0x00,
- 0x80,0x40,0x20,0x1E,0x20,0x40,0x40,0x7F,0x44,0x44,0x44,0x44,0x44,0x40,0x40,0x00,/*"定",0*/
- 0x00,0xFC,0x84,0x84,0x84,0xFC,0x00,0x10,0x10,0x10,0x10,0x10,0xFF,0x10,0x10,0x00,
- 0x00,0x3F,0x10,0x10,0x10,0x3F,0x00,0x00,0x01,0x06,0x40,0x80,0x7F,0x00,0x00,0x00,/*"時",1*/
- 0x80,0x80,0x9E,0x92,0x92,0x92,0x9E,0xE0,0x80,0x9E,0xB2,0xD2,0x92,0x9E,0x80,0x00,
- 0x08,0x08,0xF4,0x94,0x92,0x92,0xF1,0x00,0x01,0xF2,0x92,0x94,0x94,0xF8,0x08,0x00,/*"器",2*/
- };
- char HZ2[]={
- 0x00,0x02,0xE2,0x22,0x22,0x22,0x22,0x3E,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,
- 0x00,0x03,0x02,0x02,0x42,0x82,0x42,0x3E,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,/*"引",0*/
- 0x00,0xFE,0x22,0x22,0xFE,0x80,0x88,0xFF,0x88,0x80,0x00,0xFC,0x04,0x04,0xFC,0x00,
- 0x80,0x7F,0x02,0x82,0xFF,0x10,0x3C,0x13,0x18,0x30,0x00,0xFF,0x04,0x08,0x07,0x00,/*"腳",1*/
- };
-
- char HZ3[]={
- 0x00,0x04,0x44,0x44,0x44,0x44,0xFC,0x22,0x22,0x22,0x22,0x23,0x02,0x00,0x00,0x00,
- 0x04,0x04,0x04,0x04,0x04,0x04,0x7F,0x82,0x82,0x82,0x82,0x82,0x82,0xF2,0x00,0x00,/*"毛",0*/
- 0x10,0x0C,0x44,0x54,0x54,0xFC,0x55,0x56,0x54,0xFC,0x54,0x54,0x44,0x14,0x0C,0x00,
- 0x11,0x11,0x09,0x05,0x03,0x21,0x25,0x45,0x49,0x91,0x03,0x05,0x09,0x11,0x11,0x00,/*"寒",1*/
- 0x00,0x00,0x00,0xBE,0x2A,0x2A,0x2A,0xEA,0x2A,0x2A,0x2A,0x3E,0x00,0x00,0x00,0x00,
- 0x00,0x44,0x42,0x49,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x49,0x41,0x40,0x00,0x00,/*"星",2*/
- };
- void Timer1IntHandler(void)
- {
- // Clear the timer interrupt
- TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
- if(GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_6))
- {
- GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 0<<6); // 紅LED燈:亮
- }
- else
- {
- GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_6, 1<<6); // 紅LED燈:滅
- }
- }
- //*****************************************************************************
- //
- // The main application.
- // Blink the led
- // led2-PA4
- //
- //*****************************************************************************
- int
- main(void)
- {
- uint32_t ui32Period;
- i=0;
- //
- // The FPU should be enabled because some compilers will use floating-
- // point registers, even for non-floating-point code. If the FPU is not
- // enabled this will cause a fault. This also ensures that floating-
- // point operations could be added to this application and would work
- // correctly and use the hardware floating-point unit. Finally, lazy
- // stacking is enabled for interrupt handlers. This allows floating-
- // point instructions to be used within interrupt handlers, but at the
- // expense of extra stack usage.
- FPUEnable();
- FPULazyStackingEnable();
- //
- // 注:下面為用PLL和不用PLL設置系統時鐘的方法
- // 啟用 PLL(通過合理設置,最高可到 80MHz),設置系統時鐘為 40 MHz
- SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
- // 不啟用 PLL(不超過外接晶振頻率,本核心板為 16MHz),設置系統時鐘為 16 MHz
- //SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
-
- // LED 引腳初始化
- // 設置 PA4 為輸出
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // 使能 GPIO A模塊
- GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_4); // PA4 設置為輸出
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_4,1<<4); // 綠 LED 燈初始態:滅
- // 設置 PD6 為輸出
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // 使能 GPIO D模塊
- GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_6); // PD6 設置為輸出
- GPIOPinWrite(GPIO_PORTD_BASE,GPIO_PIN_6,1<<6); // 紅 LED 燈初始態:滅
- //
- // Timer0 init
- SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
- TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
- // Timer1 init
- SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);
- TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
-
- //
- UC1701Init(60000);
- UC1701Clear();
- UC1701ChineseDispaly(0, 1, 7,HZ);
- UC1701ChineseDispaly(1, 1, 3,HZ1);
- UC1701CharDispaly(1, 7, "0,");
- UC1701ChineseDispaly(1, 9, 2,HZ2);
- UC1701CharDispaly(1, 13, "PA4");
- UC1701CharDispaly(2, 1, "Fre=12,Duty=12");
- UC1701ChineseDispaly(3, 1, 3,HZ3);
- // Timer delay period
- ui32Period = (SysCtlClockGet()); // 獲取系統運行頻率,單位為 Hz
- TimerLoadSet(TIMER0_BASE, TIMER_A, (ui32Period/1200000)-1); // 設置 Timer0 溢出周期
- TimerLoadSet(TIMER1_BASE, TIMER_A, ui32Period/3 -1); // 設置 Timer1 溢出周期
- //
- // interrupt enable--timerxA
- IntEnable(INT_TIMER0A); //Enables a timer interrupt
- //Enables individual timer interrupt sources
- TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
- IntEnable(INT_TIMER1A); //Enables a timer interrupt
- //Enables individual timer interrupt sources
- TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
- IntMasterEnable(); //Enables the processor interrupt
- TimerIntRegister(TIMER0_BASE, TIMER_BOTH, Timer0IntHandler); // Timer0 中斷服務函數入口
- TimerIntRegister(TIMER1_BASE, TIMER_BOTH, Timer1IntHandler); // Timer1 中斷服務函數入口
- //
- // timer0 enable--This will start the timer and interrupts
- TimerEnable(TIMER0_BASE, TIMER_A); // 使能 Timer0:TIMER_A
- TimerEnable(TIMER1_BASE, TIMER_A); // 使能 Timer1:TIMER_A
-
- ui32Period = SysCtlClockGet()/40000; // 【示例】獲取系統時鐘,并 40k 分頻
- SysCtlDelay(ui32Period); // 【示例】調用系統延時函數
-
- while(1) // 無限循環(死循環)
- {
-
- }
- }
- // The end.
復制代碼
所有資料51hei提供下載:
s07-lab7B1.rar
(1.76 MB, 下載次數: 11)
2018-5-24 17:44 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|