求一段可运行的基于单片机pic 32mx795f512l 的c语言代码(流水灯)

2024-06-06 12:41:34
最佳回答
你从microchip官网上下一些pic32的例程就行啦,各种外设接口的例程都有,下面是定时中断的一个例程。在debug模式下能正常进中断,rd0接口的led闪烁表示芯片是好的#include // configuration bit settings// sysclk = 72 mhz (8mhz crystal/ fpllidiv * fpllmul / fpllodiv)// pbclk = 36 mhz// primary osc w/pll (xt+,hs+,ec+pll)// wdt off// other options are don't care//#pragma config fpllmul = mul_18, fpllidiv = div_2, fpllodiv = div_1, fwdten = off#pragma config poscmod = hs, fnosc = pripll, fpbdiv = div_2// let compile time pre-processor calculate the pr1 (period)#define fosc 72e6#define pb_div 8#define prescale 256#define toggles_per_sec1#define t1_tick (fosc/pb_div/prescale/toggles_per_sec)int main(void){ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //step 1. configure cache, wait states and peripheral bus clock// configure the device for maximum performance.// th** macro sets flash wait states, pbclk divider and drm wait states based on the specified// clock frequency. it also turns on the cache mode if **aialble.// based on the current frequency, the pbclk divider will be set at 1:2. th** knoweldge// ** required to correctly set uart baud rate, timer reload value and other time sensitive// setting.systemconfigperformance(fosc); // override pbdiv to 1:8 for th** timer example moscsetpbdiv(osc_pb_div_8); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // step 2. configure timer 1 using internal clock, 1:256 prescale opentimer1(t1_on | t1_source_int | t1_ps_1_256, t1_tick); // set up the timer interrupt with a priority of 2 configinttimer1(t1_int_on | t1_int_prior_2); // enable multi-vector interrupts intenablesystemmultivectoredint();// configure portd.rd0 = output mportdsetpinsdigitalout(bit_0); while(1);}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // step 3. configure the timer 1 interrupt handlervoid __**r(_timer_1_vector, ipl2) timer1handler(void){ // clear the interrupt flag mt1clearintflag(); // .. things to do // .. in th** case, toggle the led mportdtogglebits(bit_0);} 20210311
汇率兑换计算器

类似问答
  • akima 插值和样条插值的c语言源代码,要有注释。
    • 2024-06-06 20:01:02
    • 提问者: 未知
    akima 插值 附带的图片为运行结果 include"stdio.h include"math.h include"interpolation.h void interpolation_akima(akintep ap){ int num,k,kk,m,l;double pio,*mtr,*x,*y,u[5],p,q;num=ap->n;k=ap->k;pio=ap->t;mt...
  • 关于c语言的书籍推荐
    • 2024-06-06 01:03:56
    • 提问者: 未知
    1,选对教材,现在公认的c语言教材是谭浩强的<c程序设计>,清华大学出版社的;这本书上写的详细,易懂,把这本书搞懂; 2,给你几点建议:你可以在看书的同时做点相应的练习,也可以上级实践,自己可以找到错误并改正,多看看程序,理解一下他的运行过程,刚开始肯定有点困难,看多了就好了; 3,把课本看完后,就可以借一本c程序实例进行巩固,题做多了肯定就没问题了;希望你能够学好c语言,很重要的!!
  • 求 c语言选择排序法和 冒泡排序法代码!
    • 2024-06-06 01:37:01
    • 提问者: 未知
    选择排序: void select_sort(int a[],int n)/传入数组的要排序的元素个数 {int i,j,min,t;for(i=0;i;i+) { min=i;min:当前最小值下标 for(j=i+1;j;j+)/扫描余下的部分 if(a[min]>a[j])/若有其它元素更小,就记录其下标 min=j;if(min!i)/保若最小值不在排序区首位,就换到首位 {t=a[...
  • 请问51单片机最大可以运行多大的程序,最好是stc的,c语言
    • 2024-06-06 01:25:08
    • 提问者: 未知
    最后这个语言有点霸道哦,不过还是回答您前面好点:stc12c5a60s2可以运行大约59-60k左右的程序,子函数多,是多少?我最大的是运行了57.5k,再高就溢出了,不能正常运转,...
  • 关于c语言编程!!!
    • 2024-06-06 11:34:24
    • 提问者: 未知
    我的建议是把你的曲线的方程写出来,然后确定边界也就是说它的第一个点和最后一个点的x,y值分别是多少,根据第一个点的x值确定你的起始点就是x,接着确定步长,最后根据你的...
  • 求k桶法排序的c语言代码
    • 2024-06-06 12:57:20
    • 提问者: 未知
    k桶法:k桶法有两个主要步骤:分桶,整合。分桶:把n个数依次放入k个桶中,除了第k个桶外,放入前k-1个桶中的数都要求后一个大于前一个。分桶的具体规则如下: 第1个数放入...
  • 求c语言编程模拟-波的俩分干涉-源代码
    • 2024-06-06 20:24:39
    • 提问者: 未知
    #include<stdio.h> #include<stdlib.h> #include<math.h> void main(void) { double r1,r2; // 2个距离double l,p1,p2,p; // 波长,波1相位,波2相位,p处合成相位double a1,a2,a,y; // 波1振幅,波2振幅,p处合成振幅,y 是随时间变化的幅...
  • 谁有魔方c语言源代码?
    • 2024-06-06 07:00:38
    • 提问者: 未知
    #include#define maxline 100//最大行#define maxcolumn 100//最大列int main(){int a[maxline][maxline]={0}; int i,j,n,k;printf("输入行或列的值: ");scanf("%d",&n);i=0;j=n/2;for(k=1;k
  • c语言灯塔问题
    • 2024-06-06 04:41:10
    • 提问者: 未知
    展开全部#include main() {int a1,q=2;for(a1=1;a1+) if(a1*(1-pow(q,8))/(1-q)=765)/*等比数列求前n项和公式,这里n=8,q为公比*/ printf("%d",a1);}(5)等比求和: ①当q≠1时, 或 ②当q=1时, 引用自网页链接(高中数学)
  • 求c语言编写的简单计算器程序,包括源代码,水平不要太高,简单就行。
    • 2024-06-06 17:47:02
    • 提问者: 未知
    /* 加减乘除计算器 */#include<stdio.h>void main(){ float a,b; int i; printf("输入运算类型\n1.加法 2.减法 3.乘法 4.除法\n"); scanf("%d",&i); printf("输入参与的运算因数(空格键分隔):\n&quo...
汇率兑换计算器

热门推荐
热门问答
最新问答
推荐问答
新手帮助
常见问题
房贷计算器-九子财经 | 备案号: 桂ICP备19010581号-1 商务联系 企鹅:2790-680461

特别声明:本网为公益网站,人人都可发布,所有内容为会员自行上传发布",本站不承担任何法律责任,如内容有该作者著作权或违规内容,请联系我们清空删除。