查看: 1776|回复: 5
|
PIC18F4550 connect to GSM
[复制链接]
|
|
学校final project 做关于 flood monitoring system,
就是从 sensor 去 PIC 做input, 然后 3个output 1. LED lamp, 2. Buzzer, 3.GSM,
找来找去就是找不到关于我们project 的coding ... =.=
又没有大大可以帮忙下?
跟着的是我们project的 circuit .gif)
|
|
|
|
|
|
|
|

楼主 |
发表于 21-2-2013 03:15 PM
|
显示全部楼层
#include<p18F4550.h>
//chip config ///////////////////////////////////////////////
#pragma config FOSC = HS //HS oscllator
#pragma config FCMEN = OFF //Fall-safe clock Monitor disabled
#pragma config IESO = OFF //Oscillator Switchover
#pragma config PWRT = OFF //PWRT disabled
#pragma config WDT = OFF //WDT disabled(control is placed on the SWDTEN bit)
#pragma config MCLRE = OFF //MCLR pin enabled;RE3 input pin disabled
#pragma config PBADEN = OFF //PORTB<4:0>pins are configured as digital I/O on reset
#pragma config LVP = OFF //Single-Supply ICSP disabled
//defines /////////////////////////////////////////////////
#define SW1 PORTBbits.RB6
#define SW2 PORTBbits.RB7
#define LEDLV1 PORTCbits.RC0
#define LEDLV2 PORTCbits.RC1
#define ALARM PORTCbits.RC4
#define GSM PORTCbits.RC6
//////////////////////////////////////////////////////////
void main(void)
{
TRISB=0B11000000; // configure RB6 and RB7 as input
TRISC=0x00; // configure RC as output
PORTC=0x00; // clear
PORTB=0B00000000; // clear
while(1)
{
if(!SW1) //if SW1 is pressed
{
LEDLV1=1;
LEDLV2=0;
ALARM=1;
GSM=0;
if(SW1==1)
{
PORTC=0x00;
}
}
if(!SW1&&!SW2) //if SW1 and SW2 is pressed
{
LEDLV1=1;
LEDLV2=1;
GSM=1;
ALARM=1;
if((SW1==1)&&(SW2==1))
{
PORTC=0x00;
}
}
}
}
如果现在我要那个 2歌button 按得时候只是 LED 亮,所有那些 buzzer GSM 都换去 LED。。。
根据我上面写的programming.... 我是想 button 1 按的时候 LED LV1 和 BUZZER 亮...俩个按得时候 全部亮..
可以请大大帮我看下我programming嘛!?
因为我一放进去programming run的时候 LED 1 @ 3 就直接亮了,LED 2 @ 4。。就闪下闪下....。。。当俩个button 按下去 就 只是 LED 1 @ 3亮罢了...
可以帮我看下问题出在那嘛!? @。@
谢谢 |
|
|
|
|
|
|
|
发表于 8-3-2013 09:20 AM
|
显示全部楼层
1)请问有做push button debounce 吗?
2)请问什么compiler? ccs?
3)如果是ccs的话,个人建议 PORTCbits.RCX 换去 PIN_CX , 和用 output_low/output_high 去drive你的port |
|
|
|
|
|
|
|

楼主 |
发表于 14-3-2013 02:25 PM
|
显示全部楼层
Ic3tAe 发表于 8-3-2013 09:20 AM 
1)请问有做push button debounce 吗?
2)请问什么compiler? ccs?
3)如果是ccs的话,个人建议 PORTCb ...
1. 什么来的 >.< 新手不是很会
2. MPLAB...
3.我想问如果用PIC16F 和 18F...他们的circuit和 program 是不是不同的? 不同在于什么地方
|
|
|
|
|
|
|
|
发表于 20-3-2014 12:28 PM
|
显示全部楼层
你好啊楼主..
事隔一年了不知道你还需要解答不 ==
其实很简单...使用else if
其实问题出在
if(!SW1)
if(!SW1&&!SW2)
》》if 这里
你要set一个顺序给program
要不然它读了if(!SW1) 就会自动ignore if(!SW1&&!SW2)
你两个一起按
它自然不会给你两个button的respond
program应该这样写
if(!SW1&&!SW2)
然后
else if(!SW1)
先读取sw1和sw2
如果sw2没按 才读取 sw1
这样就没问题了 =D
|
|
|
|
|
|
|
|
发表于 16-6-2014 02:50 AM
|
显示全部楼层
楼主,你schematic里的switch pull-up resistor接不对,请检查一下。 本帖最后由 jimmysheng91 于 16-6-2014 02:52 AM 编辑
|
评分
-
查看全部评分
|
|
|
|
|
|
| |
本周最热论坛帖子
|