飞思卡尔后背资料8
- 格式:ppt
- 大小:419.50 KB
- 文档页数:13


第一章搭建实验环境1、实验电路板及下载器实物图片2、实验电路图本实验图包含两大部分,分别是CPU.SCH和实验资源.SCH。
CPU采用飞思卡尔8位单片机MC9S08JM60CLD,(电路图介绍)图1-3实验资源部分电路图1-4LCD串口1602液晶电路图1-5RS232接口电路图1-6数码管显示电路图1-7发光管、ad转换以及按键电路图1-83、集成开发软件环境的建立1〉运行文件CW_MCU_V6_3_SE.EXE,在电脑C盘安装飞思卡尔8位(及简化32位)单片机集成开发环境codewarrior6.3版本2〉运行USBDM_4_7_0i_Win,这个程序会在c盘的程序文件夹下增加一个目录C:\Program Files\pgo\USBDM 4.7.0,在这个目录下a>C:\Program Files\pgo\USBDM 4.7.0\FlashImages\JMxx下的文件USBDM_JMxxCLD_V4.sx是下载器的固件文件;b>C:\Program Files\pgo\USBDM4.7.0\USBDM_Drivers\Drivers下有下载器的usb驱动.因此在插入usb下载器,电脑提示发现新的usb硬件的时候,选择手动指定驱动安装位置到以上目录即可。
3〉运行USBDM_4_7_0i_Win之后,还会在目录:C:\Program Files\Freescale\CodeWarrior for Microcontrollers V6.3\prog\gdi下增加一些文件,从修改时间上来看,增加了6个文件,这些文件是为了在codewarrior集成开发环境下对usb下载器的调试、下载的支持。
4、C语言编程基础第二章 LED闪烁程序编写过程1、新建工程运行单片机集成开发环境codewarrior IDE出现如下界面●Create New Project :创建一个新项目工程●Load Example Project :加载一个示例工程●Load Previous Project :加载以前创建过的工程●Run Getting started Tutorial:运行CodeWarrior软件帮助文档●Start Using CodeWarrior:立刻使用CodeWarrior点击Create New project按钮,以创建一个新的工程,出现选择CPU的界面如下,请选择HCS08/HCS08JM Family/MC9S08JM60,在右边的Connection窗口可以选择最后一个开源下载器HCS08 Open Source BDM。
MC9S08AW60子程序之FLASH凤凰涅槃发表于 2008-12-16 3:24:00推荐/*子程序*/#i nclude <hidef.h> /* for EnableInterrupts macro */#i nclude "derivative.h" /* include peripheral declarations */#define Page_Erase PGM[21]=0x40; temp = ((unsigned char(*)(unsigned int))(PGM))#define Program_Byte PGM[21]=0x20; temp = ((unsigned char(*)(unsigned int, unsigned char))(P GM))//Array of opcode instructions of the Erase/Program in the HCS08 familyvolatile unsigned char PGM[59] = {0x87,0xC6,0x18,0x25,0xA5,0x10,0x27,0x08,0xC6,0x18,0x25,0xAA,0x10,0xC7,0x18,0x25,0x9E,0xE6,0x01,0xF7,0xA6,0x20,0xC7,0x18,0x26,0x45,0x18,0x25,0xF6,0xAA,0x80,0xF7,0x9D,0x9D,0x9D,0x9D,0x45,0x18,0x25,0xF6,0xF7,0xF6,0xA5,0x30,0x27,0x04,0xA6,0xFF,0x20,0x07,0xC6,0x18,0x25,0xA5,0x40,0x27,0xF9,0x8A,0x81};/* The opcode above represents this set of instructionsif (FSTAT&0x10){ //Check to see if FACCERR is setFSTAT = FSTAT | 0x10; //write a 1 to FACCERR to clear}(*((volatile unsigned char *)(Address))) = data; //write to somewhere in flashFSTAT = FSTAT | 0x80; //Put FCBEF at 1._asm NOP; //Wait 4 cycles_asm NOP;_asm NOP;_asm NOP;if (FSTAT&0x30){ //check to see if FACCERR or FVIOL are setreturn 0xFF; //if so, error.}while ((FSTAT&0x40)==0){ //else wait for command to complete;}*/void MCU_init(void){/* ### Init_FLASH init code *//* FCDIV: DIVLD=0,PRDIV8=0,DIV5=0,DIV4=1,DIV3=0,DIV2=0,DIV1=1,DIV0=1 */FCDIV = 0x13;} /*MCU_init*/void main(void){unsigned char temp,i;MCU_init();PTFDD = 0xFF;//EnableInterrupts;/* include your code here */temp = Page_Erase(0xF000);if(temp==0xFF){PTFD=0x01;}for(i=0; i< 255; i++){temp = Program_Byte(0xF000+i,i);if(temp==0xFF){PTFD=0x01;}}//Program_Byte(0xFFBF,0x40); security flash and ram after reset for(;;){__RESET_WATCHDOG(); /* feeds the dog */} /* loop forever *//* please make sure that you never leave this *//* please make sure that you never leave this */}MC9S08AW60子程序之KBI凤凰涅槃发表于 2008-12-16 3:22:00推荐/*头文件*/void KBI_Init(void);/*KBI子程序*/#i nclude <MC9S08AW60.h> /* I/O map */void KBI_Init(void){/* ### Init_KBI init code *//* KBI1SC: KBIE=0 */KBI1SC &= (unsigned char)~0x02;/* KBI1PE: KBIPE7=0,KBIPE6=0,KBIPE5=1,KBIPE4=0,KBIPE3=0,KBIPE2=0,KBIPE1=0,KBIPE0=0 */ KBI1PE = 0x20;/* KBI1SC: KBACK=1 */KBI1SC |= (unsigned char)0x04;/* KBI1SC: KBIE=1 */KBI1SC |= (unsigned char)0x02;}/*** ===================================================================** Interrupt handler : isrKBI**** Deion :** User interrupt service routine.** Parameters : None** Returns : Nothing** ===================================================================*/interrupt 22 void isrKBI(void){/* Write your interrupt code here ... */KBI1SC_KBACK = 1; // Clears KBI interrupt flag (KBF)PTFD_PTFD0 = ~PTFD_PTFD0;}/*主程序*/#i nclude <hidef.h> /* for EnableInterrupts macro */#i nclude "derivative.h" /* include peripheral declarations */#i nclude "KBI.h"void MCU_init(void) /* Device initialization declaration */ {KBI_Init();/* ### Init_GPIO init code *//* PTFDD: PTFDD0=1 */PTFDD |= (unsigned char)0x01;}void main(void){/* Uncomment this call after using Device Initialization to use the generated code */MCU_init();/* include your code here */EnableInterrupts; /* enable interrupts */for(;;){__RESET_WATCHDOG(); /* feeds the dog */} /* loop forever *//* please make sure that you never leave this */}MC9S08AW60子程序之PWM凤凰涅槃发表于 2008-12-16 3:17:00推荐/*头文件*/void PWM_Init(void);void PWM_SetDuty(word duty);void PWM_SetPeriod(word period);/*子程序*/#i nclude <MC9S08AW60.h>void PWM_Init(void){/* ### Init_TPM init code */TPM1MOD = 0x00;TPM1C2V = 0x8000;/* TPM1C2SC: CH2F=0,CH2IE=0,MS2B=1,MS2A=0,ELS2B=0,ELS2A=1 */TPM1C2SC = 0x24;/* TPM1SC: TOF=0,TOIE=0,CPWMS=0,CLKSB=0,CLKSA=1,PS2=0,PS1=1,PS0=1 */ TPM1SC = 0x0B;}void PWM_SetDuty(word duty){TPM1C2V = duty;}void PWM_SetPeriod(word period){TPM1MOD = period;}/*主程序*/#i nclude <hidef.h> /* for EnableInterrupts macro */#i nclude "derivative.h" /* include peripheral declarations */#i nclude "PWM.h"word prd = 0xFFFF;word dty = 0x8000;void MCU_init(void) /* Device initialization declaration */{PWM_Init();}void main(void) {/* Uncomment this call after using Device Initializationto use the generated code */MCU_init();EnableInterrupts; /* enable interrupts *//* include your code here */for(;;){PWM_SetPeriod(prd);PWM_SetDuty(dty);__RESET_WATCHDOG(); /* feeds the dog */} /* loop forever *//* please make sure that you never leave this */}MC9S08AW60子程序之RTI凤凰涅槃发表于 2008-12-16 3:15:00推荐/*头文件*/void RTI_Init(void);/*RTI子程序*/#i nclude <MC9S08AW60.h>void RTI_Init(void){/* SRTISC: RTIF=0,RTIACK=0,RTICLKS=0,RTIE=1,??=0,RTIS2=1,RTIS1=1,RTIS0=1 */SRTISC = 0x17; /* Run RTI (select clock source, set frequncy and enable interrupt )*/ }interrupt 25 void isrRTI(void){SRTISC_RTIACK = 1; /* Reset real-time interrupt request flag */PTFD_PTFD0 = ~PTFD_PTFD0;}/*主程序*/void main(void){/* Uncomment this call after using Device Initializationto use the generated code */MCU_init();EnableInterrupts; /* enable interrupts *//* include your code here */for(;;){__RESET_WATCHDOG(); /* feeds the dog */} /* loop forever *//* please make sure that you never leave this */}MC9S08AW60子程序之SCI凤凰涅槃发表于 2008-12-16 3:10:00/*头文件*/void SCI1_Init(void);void SCI1_SendChar(byte data);void SCI1_ReceiveChar(byte *data);void printf0(byte *str);/*串口子程序*/#i nclude <MC9S08AW60.h>void SCI1_Init(void){/* ### Init_SCI init code *//* SCI1BD: SBR12=0,SBR11=0,SBR10=0,SBR9=0,SBR8=0,SBR7=0,SBR6=0,SBR5=0,SBR4=1,SBR3=1,SBR2= 0,SBR1=1,SBR0=0 */SCI1BD = 0x1A;/* SCI1C1: LOOPS=0,SCISWAI=0,RSRC=0,M=0,WAKE=0,ILT=0,PE=0,PT=0 */SCI1C1 = 0x00;/* SCI1C2: TIE=0,TCIE=0,RIE=1,ILIE=0,TE=1,RE=1,RWU=0,SBK=0 */SCI1C2 = 0x2C;/* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */ SCI1C3 = 0x00;/* SCI1S2: BRK13=0,RAF=0 */SCI1S2 = 0x00;}void SCI1_ReceiveChar(byte *data){*data = SCI1D;}void SCI1_SendChar(byte data){while(!SCI1S1_TDRE);SCI1D = data;}void printf0(char *str){while((*str != '\r')){SCI1_SendChar(*str);if(*str++=='\n')SCI1_SendChar('\r');}}interrupt 17 void isrSCI1Receive(void){byte data;SCI1S1_RDRF;SCI1_ReceiveChar(&data);printf0("\nthis is \r");SCI1_SendChar(data);SCI1_SendChar('!');}/*主程序*/#i nclude <hidef.h> /* for EnableInterrupts macro */#i nclude "derivative.h" /* include peripheral declarations */#i nclude "SCI.h"void MCU_init(void) /* Device initialization declaration */ {SCI1_Init();}void main(void) {/* Uncomment this call after using Device Initialization to use the generated code */MCU_init();EnableInterrupts; /* enable interrupts *//* include your code here */printf0("\nhello, MC9S08AW60!\r");for(;;){__RESET_WATCHDOG(); /* feeds the dog */} /* loop forever *//* please make sure that you never leave this */}MC9S08AW60子程序之ADC凤凰涅槃发表于 2008-12-16 3:26:00推荐/*头文件*/void ADC_Init(void);/*子程序*/#i nclude <MC9S08AW60.h>void ADC_Init(void){/* ### Init_ADC init code *//* APCTL2: ADPC15=0,ADPC14=0,ADPC13=0,ADPC12=0,ADPC11=0,ADPC10=0,ADPC9=0,ADPC8=1 */APCTL2 = 0x01;/* AD1SC2: ADACT=0,ADTRG=0,ACFE=0,ACFGT=0 */AD1SC2 = 0x00;/* AD1CV: ADCV9=0,ADCV8=0,ADCV7=0,ADCV6=0,ADCV5=0,ADCV4=0,ADCV3=0,ADCV2=0,ADCV1=0,ADCV0=0 */AD1CV = 0x00;/* AD1CFG: ADLPC=0,ADIV1=0,ADIV0=0,ADLSMP=0,MODE1=0,MODE0=0,ADICLK1=0,ADICLK0=0 */AD1CFG = 0x00;/* AD1SC1: COCO=0,AIEN=1,ADCO=1,ADCH4=0,ADCH3=1,ADCH2=0,ADCH1=0,ADCH0=0 *///AD1SC1 = 0x68;AD1SC1=0x08;}/*interrupt 23 void isrADC(void){PTFD = AD1RL;}*//*主程序*/#i nclude <hidef.h> /* for EnableInterrupts macro */#i nclude "derivative.h" /* include peripheral declarations */#i nclude "ADC.h"void MCU_init(void) /* Device initialization declaration */{ADC_Init();/* ### Init_GPIO init code *//* PTFDD: PTFDD = 0xFF */PTFDD = (unsigned char)0xFF;}void main(void){/* Uncomment this call after using Device Initializationto use the generated code */MCU_init();EnableInterrupts; /* enable interrupts *//* include your code here */for(;;){__RESET_WATCHDOG(); /* feeds the dog */} /* loop forever *//* please make sure that you never leave this */}串行通信实例这是一个单片机C51串口接收(中断)和发送例程,可以用来测试51单片机的中断接收和查询发送。