生活:翻出來兩張“文物”

翻出來兩張文物,想當年AVR的火熱程度不亞於如今的STM32,結果直至今天基本消聲匿跡。滿滿的回憶,最後悔的是DSP這張光盤沒有認真的學習。在這裏插入圖片描述
AVR的一個閃爍LED燈的程序,沒有工程概念,一個文件裏邊寫所有程序,差評。


/*********************************************
Demo_5_2.c
Chip type           : ATmega16
Program type        : Application
Clock frequency     : 4.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 256
*********************************************/

#include <mega16.h>				// 包括器件配置定義的頭文件,不能缺少
	#ifndef __SLEEP_DEFINED__
	#define __SLEEP_DEFINED__
	.EQU __se_bit=0x40
	.EQU __sm_mask=0xB0
	.EQU __sm_powerdown=0x20
	.EQU __sm_powersave=0x30
	.EQU __sm_standby=0xA0
	.EQU __sm_ext_standby=0xB0
	.EQU __sm_adc_noise_red=0x10
	.SET power_ctrl_reg=mcucr
	#endif
#include <delay.h>				// 包括延時函數定義的頭文件,使用延時函數時不能缺少

void main(void)
{
  // 定義PortC口的工作方式
  PORTC=0x01;				// PC口的第0位輸出"1",LED不亮
  DDRC=0x01;				// 定義PC口的第0位爲輸出方式

  // 主循環
  while (1)
	{
    delay_ms(1000); 		// 調用CVAVR提供的毫秒延時函數,延時1s
  	PORTC.0 = ~PORTC.0;	// PC口第0位輸出取反
  };
}

TMS0F2812 DSP的LED跑馬燈程序如下,沒有工程概念,一個文件裏邊寫所有程序,差評。

//###########################################################################
//
// FILE:	hardware.c
//
// TITLE:	DSP28 GPIO - Port B7..B0  :, software delay 
//		
//
//###########################################################################

#include "DSP281x_Device.h"

// Prototype statements for functions found within this file.

void delay_loop(long);
void Gpio_select(void);
void InitSystem(void);

void main(void)
{
	unsigned int i;
	unsigned int LED[8]= {0x0001,0x0002,0x0004,0x0008,
	                      0x0010,0x0020,0x0040,0x0080};	
	
	InitSystem();		// Initialize the DSP's core Registers
	
	// Speed_up the silicon A Revision. 
	// No need to call this function for Rev. C  later silicon versions
	
	Gpio_select();		// Setup the GPIO Multiplex Registers

	while(1)
	{    
  	    for(i=0;i<14;i++){
    	if(i<7) 	GpioDataRegs.GPBDAT.all = LED[i];
    	  else  	GpioDataRegs.GPBDAT.all = LED[14-i]; 
    	delay_loop(1000000);
    	}
    }
} 	

void delay_loop(long end)
{
	long i;
	for (i = 0; i < end; i++);
	EALLOW;
	SysCtrlRegs.WDKEY = 0x55;
	SysCtrlRegs.WDKEY = 0xAA;
	EDIS;
	
}

void Gpio_select(void)
{
	EALLOW;
	GpioMuxRegs.GPAMUX.all = 0x0;	// all GPIO port Pin's to I/O
    GpioMuxRegs.GPBMUX.all = 0x0;   
    GpioMuxRegs.GPDMUX.all = 0x0;
    GpioMuxRegs.GPFMUX.all = 0x0;		 
    GpioMuxRegs.GPEMUX.all = 0x0; 
    GpioMuxRegs.GPGMUX.all = 0x0;			
										
    GpioMuxRegs.GPADIR.all = 0x0;	// GPIO PORT  as input
    GpioMuxRegs.GPBDIR.all = 0x00FF;	// GPIO Port B15-B8 input , B7-B0 output
    GpioMuxRegs.GPDDIR.all = 0x0;	// GPIO PORT  as input
    GpioMuxRegs.GPEDIR.all = 0x0;	// GPIO PORT  as input
    GpioMuxRegs.GPFDIR.all = 0x0;	// GPIO PORT  as input
    GpioMuxRegs.GPGDIR.all = 0x0;	// GPIO PORT  as input

    GpioMuxRegs.GPAQUAL.all = 0x0;	// Set GPIO input qualifier values to zero
    GpioMuxRegs.GPBQUAL.all = 0x0;
    GpioMuxRegs.GPDQUAL.all = 0x0;
    GpioMuxRegs.GPEQUAL.all = 0x0;
    EDIS;
}     

void InitSystem(void)
{
   	EALLOW;
   	SysCtrlRegs.WDCR= 0x00AF;		// Setup the watchdog 
   									// 0x00E8  to disable the Watchdog , Prescaler = 1
   									// 0x00AF  to NOT disable the Watchdog, Prescaler = 64
   	SysCtrlRegs.SCSR = 0; 			// Watchdog generates a RESET	
   	SysCtrlRegs.PLLCR.bit.DIV = 10;	// Setup the Clock PLL to multiply by 5
    
   	SysCtrlRegs.HISPCP.all = 0x1; // Setup Highspeed Clock Prescaler to divide by 2
   	SysCtrlRegs.LOSPCP.all = 0x2; // Setup Lowspeed CLock Prescaler to divide by 4
      	
   	// Peripheral clock enables set for the selected peripherals.   
   	SysCtrlRegs.PCLKCR.bit.EVAENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.EVBENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.SCIAENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.SCIBENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.MCBSPENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.SPIENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.ECANENCLK=0;
   	SysCtrlRegs.PCLKCR.bit.ADCENCLK=0;
   	EDIS;
}

//===========================================================================
// End of SourceCode.
//===========================================================================


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章