|
【练习】PIC 编程 - LED闪灯 (功力挑战)
[复制链接]
|
|
发表于 5-4-2009 07:01 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 5-4-2009 07:51 PM
|
显示全部楼层
回复 121# fritlizt 的帖子
但我在c++里只学到一些简单的如:关于char,sum那些等等。 那有什么website可以让我从基本学起。。。 |
|
|
|
|
|
|
|
发表于 5-4-2009 10:21 PM
|
显示全部楼层
不好意思。忘了写
来这里讨论吧。不然就好像文不对题。
初学者的问题。 - Eneccc
[ 本帖最后由 fritlizt 于 5-4-2009 10:22 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 6-4-2009 07:29 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 25-4-2009 10:34 PM
|
显示全部楼层
Q3 的答案
参考rothmans,然后自己写的第三题答案。 16f628a, 4MHz, Hi-tech 9.6 compiler, mplab IDE
#include <pic.h>
#define LED1_on 5 /* 50mS */
#define LED2_on 30 /* 300mS */
#define LED3_on 1 /* 10mS */
unsigned char temp0=0;
unsigned char period1=0;
unsigned char temp2=0;
unsigned char period2=0;
unsigned char temp4=0;
unsigned char period3=0;
void hardware_initialize(void);
void main(void)
{
hardware_initialize();
ei();
PORTB = 0x07; //turn on all RB0 - RB2
while(1)
{
if(temp0==LED1_on)
{
PORTB &= ~0x01; //turn off after 50ms
}
if(period1==100)
{ //turn RB0 on and reset variable again for another cycle
PORTB |= 0x01;
period1 = 0;
temp0=0;
}
if(temp2==LED2_on)
{
PORTB &= ~0x02; //turn RB1 off after 300ms
}
if(period2==200)
{ //turn RB1 on and reset variable again for another cycle
PORTB |= 0x02;
period2=0;
temp2=0;
}
if(temp4==LED3_on)
{
PORTB &= ~0x04; //turn RB2 off after 10ms
}
if(period3==10)
{ //turn RB2 on and reset variable again for another cycle
PORTB |= 0x04;
period3 = 0;
temp4 = 0;
}
}
}
void hardware_initialize(void)
{
PCON = 0x0B; /* OSCF = 4MHz, Not PWR ON @ BOD Reset. */
PORTA = 0xFF;
PORTB = 0x00;
CMCON = 0x07;
INTCON = 0x20; /* Enable Timer 0 Interrupt */
PIE1 = 0x00; /* Interrupt Enable Bit */
OPTION = 0x05; /* Disable PORTA Pull-up */
TRISA = 0xFF;
TRISB = 0x00;
TMR0 = 0x63;
}
static void interrupt isr(void)
{
if(T0IE && T0IF)
{
TMR0 = 0x63;
temp0++;
period1++;
temp2++;
period2++;
temp4++;
period3++;
T0IF=0;
}
} |
评分
-
查看全部评分
|
|
|
|
|
|
|

楼主 |
发表于 26-4-2009 08:04 AM
|
显示全部楼层
原帖由 suyy10 于 25-4-2009 10:34 PM 发表 
参考rothmans,然后自己写的第三题答案。 16f628a, 4MHz, Hi-tech 9.6 compiler, mplab IDE
没有HiTech compiler, 可不可以自己模拟? 或贴上hex? |
|
|
|
|
|
|
|
发表于 26-4-2009 09:35 AM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 27-4-2009 10:44 AM
|
显示全部楼层
参考rothmans,然后自己写的第三题答案。 16f628a, 4MHz, Hi-tech 9.6 compiler, mplab IDE
哇·~~ 和Rothmans 大大的几乎完全一样。。。
我没有时间去检查对照源码, 可能Rothmans大大可以帮忙检查你的源码。
不过先奖励你, 但如果大家有异议, 可以提出或PM我。
 |
|
|
|
|
|
|
|
发表于 27-4-2009 07:29 PM
|
显示全部楼层
原帖由 pic 于 27-4-2009 10:44 AM 发表 
哇·~~ 和Rothmans 大大的几乎完全一样。。。
我没有时间去检查对照源码, 可能Rothmans大大可以帮忙检查你的源码。
不过先奖励你, 但如果大家有异议, 可以提出或PM我。
http://my-primesoft.com/cari/ ...
谢谢 。我只用Rothmans 的 16f628a initialization. C code 是我自己写的。 Rothmans 也没把第三题源码贴上来啊~timing 不是那么准,因为用interrupt. 如果用software delay 可以更准确! |
|
|
|
|
|
|
|
发表于 4-5-2009 09:01 PM
|
显示全部楼层
那请问一下,c++ 跟c 是一样的吗?  |
|
|
|
|
|
|
|

楼主 |
发表于 5-5-2009 08:51 AM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 5-5-2009 07:29 PM
|
显示全部楼层
|
|
|
|
|
|
|

楼主 |
发表于 5-5-2009 07:41 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 5-5-2009 08:57 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 5-5-2009 09:53 PM
|
显示全部楼层
回复 133# pic 的帖子
哦是这样咯!那c++也是可以写出来吗?  |
|
|
|
|
|
|
|
发表于 5-5-2009 09:55 PM
|
显示全部楼层
回复 134# fritlizt 的帖子
会一点吧!c++去年在学校有学过。所以我想在提升它。  |
|
|
|
|
|
|
|
发表于 6-5-2009 09:44 AM
|
显示全部楼层
据我所知,PIC 暂时还没有 C++ 的 compiler 吧。还是有了我不知道? |
|
|
|
|
|
|
|
发表于 6-5-2009 07:12 PM
|
显示全部楼层
原帖由 waiweng83 于 6-5-2009 09:44 AM 发表 
据我所知,PIC 暂时还没有 C++ 的 compiler 吧。还是有了我不知道?
如果c没有的话,那c++学来怎么? |
|
|
|
|
|
|
|
发表于 7-5-2009 12:33 AM
|
显示全部楼层
想问一下,学校学的 C++,有没有学到 class,object / instance,inheritance 之类的东西?如果没有的话,那和 C 是没有多大的差别的。 |
|
|
|
|
|
|
|
发表于 20-5-2009 07:52 PM
|
显示全部楼层
问个问题,如果我在picc 里
TRISA=0xFF; //port a = input
PORTA=0x00;
我的porta是接去+5v ,和resistor串联(logic high,从头到尾都接着)
这时PORTA=0x00还是0xFF呢?
就算我打了PORTA=0x00;他还是会变成0xFF吗? |
|
|
|
|
|
|
| |
本周最热论坛帖子
|