![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
The code below is a simple one to turn the LED on for 1 second and then off for 1 second. External crystal of 10MHz is used and the PLL is turned on which brings the FOSC up to 40MHz. However when I program and run the code, The LED appears to stay ON for only 1/4 of a second.
Am I missing something..? Thanks. Code:
#include <p18F4620.h>
#include <delays.h>
#include <stdio.h>
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config LVP = OFF
#pragma config OSC = HSPLL
#define CLOCK_FREQ (40000000ul) // Hz
void main()
{
TRISB = 0x00;
while(1)
{
PORTBbits.RB0 = 1;
Delay10KTCYx(1000);
PORTBbits.RB0 = 0;
Delay10KTCYx(1000);
}
}
|
|
|
|
|
|
|
(permalink) |
|
Hi,
I don't use C18. Is it because Delay10KTCYx works up to 255 only? I mean Delay10KTCYx(255). Use LAT registers for outputting as good practice, but it's okay here.
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
What compiler are you using?
__________________
Spency. PIC Micro's - Your mind is the limit PIC's and interfacing with other devices - a PIC Basic Guide @ digital-diy.net |
|
|
|
|
|
|
(permalink) |
|
Yes I got it! From MPLAB C18 Libraries page 143.
Code:
void Delay10KTCYx( unsigned char unit );
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
Sorry for double post..
Refer to the post below.. Last edited by MrNobody; 29th April 2008 at 07:17 AM. |
|
|
|
|
|
|
(permalink) |
|
Thanks..
In the code below, I have commented the PLL and change the FOSC to 10MHZ. Again, I use 10MHz crystal for the PIC. I have also changed the delay from 1000 to 250 so that it is within 8 bit. Again, the code is to turn the LED ON for 1 second and then OFF for 1 second. However, the problem still remain.. BTW, I am using C18 compiler. I have also attached the hex file and the asm code. Code:
#include <p18F4620.h>
#include <delays.h>
#include <stdio.h>
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config LVP = OFF
//#pragma config OSC = HSPLL
#define CLOCK_FREQ (10000000ul) // Hz
void main()
{
TRISB = 0x00;
while(1)
{
PORTBbits.RB0 = 1;
Delay10KTCYx(250);
PORTBbits.RB0 = 0;
Delay10KTCYx(250);
}
}
Code:
1: #include <p18F4620.h>
2: #include <delays.h>
3: #include <stdio.h>
4:
5: #pragma config WDT = OFF
6: #pragma config MCLRE = ON
7: #pragma config LVP = OFF
8: //#pragma config OSC = HSPLL
9: #define CLOCK_FREQ (10000000ul) // Hz
10:
11: void main()
12: {
13: TRISB = 0x00;
00F8 6A93 CLRF 0xf93, ACCESS
14: while(1)
0112 D7F3 BRA 0xfa
15: {
16: PORTBbits.RB0 = 1;
00FA 8081 BSF 0xf81, 0, ACCESS
17: Delay10KTCYx(250);
00FC 0EFA MOVLW 0xfa
00FE 6EE6 MOVWF 0xfe6, ACCESS
0100 EC65 CALL 0xca, 0
0102 F000 NOP
0104 52E5 MOVF 0xfe5, F, ACCESS
18: PORTBbits.RB0 = 0;
0106 9081 BCF 0xf81, 0, ACCESS
19: Delay10KTCYx(250);
0108 0EFA MOVLW 0xfa
010A 6EE6 MOVWF 0xfe6, ACCESS
010C EC65 CALL 0xca, 0
010E F000 NOP
0110 52E5 MOVF 0xfe5, F, ACCESS
20: }
21: }
0114 0012 RETURN 0
|
|
|
|
|
|
|
(permalink) |
|
I had a problem on the PIC12F629 that the LEDs wouldnt flash. I solved it by putting :
Code:
GPIO = 0; // Turn off all pins Code:
PORTB = 0; // Turn off all pins
__________________
Simplicity rules Good enought - its perfect ?? 2 Gig of free online backup space Are you a Chemist? |
|
|
|
|
|
|
(permalink) |
|
hi every one i have aproblem of this code , but i dont know what it is i need some one to help me please
void main() { PORTB=0; TRISB=0;//as output TRISD=1;//as input while(1) { if (PORTD.f1=1) PORTB.f7=1 ; else PORTB.f7=0; } } |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Try this Code:
void main()
{
PORTB=0;
TRISB=0;//as output
TRISD=2;//as input
while(1)
{
if (PORTD.f1=1)
PORTB.f7=1 ;
else
PORTB.f7=0;
}
}
|
||
|
|
|
|
|
(permalink) |
|
try to use this:
Code:
void main()
{
PORTB=0;
TRISB=0;//as output
TRISD=1;//as input
PORTB=0; // turn off all pins
PORTD=0: // turn off all pins
while(1)
{
if (PORTD.f1=1){
PORTB.f7=1 ;
}
else
{
PORTB.f7=0;
}
}
}
__________________
Simplicity rules Good enought - its perfect ?? 2 Gig of free online backup space Are you a Chemist? |
|
|
|
|
|
|
(permalink) |
|
Somehow (and i dont know why yet) you have turn off all ports or set all registers with all 0.
MedoLee: If you are using MikroC you have to set the config parameterse correctly ( that can be hard if its you first time)
__________________
Simplicity rules Good enought - its perfect ?? 2 Gig of free online backup space Are you a Chemist? |
|
|
|
|
|
|
(permalink) |
|
Hi MrNobody,
Even the PLL is not enabled, HS oscillator should still be selected, shouldn't it?
__________________
Superman returns..
|
|
|
|
|
|
|
(permalink) |
|
No you have to set everything in the project setup in MikroC compiler
__________________
Simplicity rules Good enought - its perfect ?? 2 Gig of free online backup space Are you a Chemist? |
|
|
|
|
|
|
(permalink) |
|
And using
Code:
TRISD=2 // just plain stupid if you want to use pins 2 and 4 as inputs and the rest as inputs it would look like this binary 00101000 and hex it would be 0x28 Code:
TRISD= 00101000 // or in hex TRISD=0x28
__________________
Simplicity rules Good enought - its perfect ?? 2 Gig of free online backup space Are you a Chemist? |
|
|
|
|
|
|
(permalink) | |
|
Quote:
Code:
TRISD=2 If you want to use pin 2 and 4 as inputs, Code:
TRISD = 0b00010100; TRISD = 0x14; TRISD = 20;
__________________
Superman returns..
|
||
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| PIC pin to MOSFET gate problem | Futterama | Electronic Projects Design/Ideas/Reviews | 7 | 8th November 2007 05:30 PM |
| Simple switching/pulse project | dbtoutfit | Electronic Projects Design/Ideas/Reviews | 2 | 1st November 2007 01:46 PM |
| Simple Robot From Scratch Parts? | GreenAce92 | Robotics Chat | 7 | 27th October 2007 11:42 PM |
| Simple? op-amp problem... | jrz126 | Electronic Projects Design/Ideas/Reviews | 2 | 20th September 2007 09:52 PM |
| PIC16F628 ... VERY SIMPLE PROBLEM | micro571 | Micro Controllers | 14 | 30th December 2004 09:51 AM |