caramoan tour package

caramoan tour package

Author Topic: Request PICMICRO codes here (C Only)  (Read 20961 times)

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Request PICMICRO codes here (C Only)
« Reply #20 on: March 25, 2009, 02:24:51 PM »
Basing from above's code, assigning percentage as parameters:
Code: [Select]
void setPWMDuty(unsigned char percent)
{
    unsigned int duty;
   
    duty = (percent * maxDuty)/100;

    CCPR1L = duty >> 2;                  // Set MSB values
    CCP1CON = ((duty & 3) << 4) | 0x0C;  // set initial duty and set PWM mode bits.
}
The Cebuano Geek

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #20 on: March 25, 2009, 02:24:51 PM »

Offline SpongeBob

  • Lead Acid Battery
  • *******
  • Posts: 660
  • Pogi/Ganda Points: 33
Re: Request PICMICRO codes here (C Only)
« Reply #21 on: March 26, 2009, 04:51:43 PM »
master zerowing, ano gamit mong compiler?

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #21 on: March 26, 2009, 04:51:43 PM »

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Request PICMICRO codes here (C Only)
« Reply #22 on: March 26, 2009, 05:13:43 PM »
For PICs: Hitech, Microchip MPLAB C18 and MPLAB C30.
ARM: ARM Realview, GCC-raisonance and GCC-winarm
8051:SDCC
CSR Bluetooth chips: Bluelab (GCC based).
The Cebuano Geek

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #22 on: March 26, 2009, 05:13:43 PM »

Offline SpongeBob

  • Lead Acid Battery
  • *******
  • Posts: 660
  • Pogi/Ganda Points: 33
Re: Request PICMICRO codes here (C Only)
« Reply #23 on: March 26, 2009, 09:03:09 PM »
bigatin pala compiler mo master zerowing,

eto pala contribution ko sa thread, galing sa LCD scrolling message

ibaibang coding style ibaibang compiler basically ganito lang magpascroll sa LCD


Code: [Select]
char msg[50]="                PICkit2 Electronicslab.ph", a, b, num_chars; //meron leading spaces para pag on blanko muna

void scroll(void){
for(a = 0;a < num_chars;a++){//num_chars galing sa strlen()
set_address(0x00);                //sa unang linya ng LCD
for(b = 0;b < 16;b++)            //kung ilan chars ng LCD, dito 16
lcd_char(msg[b + c])             //show chars
delay_ms(300);                    //scroll speed
}
}

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #23 on: March 26, 2009, 09:03:09 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Request PICMICRO codes here (C Only)
« Reply #24 on: March 26, 2009, 09:50:29 PM »
bigatin pala compiler mo master zerowing,

eto pala contribution ko sa thread, galing sa LCD scrolling message

ibaibang coding style ibaibang compiler basically ganito lang magpascroll sa LCD


Code: [Select]
char msg[50]="                PICkit2 Electronicslab.ph", a, b, num_chars; //meron leading spaces para pag on blanko muna

void scroll(void){
for(a = 0;a < num_chars;a++){//num_chars galing sa strlen()
set_address(0x00);                //sa unang linya ng LCD
for(b = 0;b < 16;b++)            //kung ilan chars ng LCD, dito 16
lcd_char(msg[b + c])             //show chars
delay_ms(300);                    //scroll speed
}
}

di ko masundan sir Rob... di ko masundana ang linyang ito:
lcd_char(msg[b + c])             //show chars
marahil msg[a+b] ???
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #24 on: March 26, 2009, 09:50:29 PM »

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Request PICMICRO codes here (C Only)
« Reply #25 on: March 26, 2009, 10:30:09 PM »
di ko masundan sir Rob... di ko masundana ang linyang ito:
lcd_char(msg[b + c])             //show chars
marahil msg[a+b] ???

tama po... a+b nga...

any way thank you for this... i'll add this to my project. it will serve as a background or sort of a screen saver when my system is idle... anyway i did not implement sleep mode. heheh ;D
so during standby mode, magdisplay na ng similar nito.;D
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline SpongeBob

  • Lead Acid Battery
  • *******
  • Posts: 660
  • Pogi/Ganda Points: 33
Re: Request PICMICRO codes here (C Only)
« Reply #26 on: March 27, 2009, 05:52:18 PM »
tama ka sir marce a+b nga, may semicolon pa after that line
kung gusto ng mas mahabang message like hundreds of characters PIC18F series ang gamitin, yun PIC16F series kasi nagrereklamo yung compiler kung lagpas na sa page ang array, meron kasi banking ang 16F

Offline jonardDAKILA

  • Size AAA Battery
  • ***
  • Posts: 62
  • Pogi/Ganda Points: 0
  • Gender: Male
  • utos ng Panginoon
    • bsece site
Re: Request PICMICRO codes here (C Only)
« Reply #27 on: April 08, 2009, 12:37:45 PM »
la po bang seven segment codes
lakas mo ky bro  -santino

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Request PICMICRO codes here (C Only)
« Reply #28 on: April 08, 2009, 04:29:57 PM »
^ check my PIC tutorial thread
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Request PICMICRO codes here (C Only)
« Reply #29 on: April 16, 2009, 10:19:13 AM »
nalilito pa po ako sa pagamit ng comparator ng f628a. sino na po nakagamit nito? papost naman po ng sample code using hitech c. TIA
if you think you can or think you can't, you're probably right -h.ford

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Request PICMICRO codes here (C Only)
« Reply #30 on: April 24, 2009, 04:13:50 PM »
pa-request naman ng routines for software SPI.. :)
like "spi_write(address, byte);" and "spi_read(address);"
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Request PICMICRO codes here (C Only)
« Reply #31 on: April 24, 2009, 04:41:35 PM »
pa-request naman ng routines for software SPI.. :)
like "spi_write(address, byte);" and "spi_read(address);"

Reading and writing to SPI port happens at the same time.
So the routine could just be "unsigned char spi_write(unsigned char data)" returning the value read after write.
A pure read could just be:
(void) spi_write(address);
value = spi_write(0x00);

A write will be:
(void) spi_write(address);
(void) spi_write(data1);
(void) spi_write(data2);

I have not made any software SPI for it will be very slow.  And for slow apps, I just use I2C instead of SPI.
SPI also has many constraints on timing depending on the slave device.  These are the inactive clock either low or high,
MSB or LSB first, and the polarity of the clock when data is shifted either low-to-high or high-to-low.

Anyway, here is one but may not be what you need but can base on it(untested):
Code: [Select]
unsigned char spi_write(unsigned char data)
{
    unsigned char v, i;

    v = 0;
    i = 8;
    CLK = 1;
   
    do {
   
        if (data & 0b10000000)
        {
            MOSI = 1;
        }
        else
        {
            MOSI = 0;
        }
       
        bit_delay();
       
        CLK = 0;
       
        v <<= 1;
        if (MISO = 1)
            v |= 1;
           
        data <<= 1;
       
        CLK = 1;
   
    } while (--i);
   
    return v;
}
The Cebuano Geek

Offline 'yus

  • Technical People
  • Nuclear Reactor
  • *****
  • Posts: 4251
  • Pogi/Ganda Points: 299
  • Gender: Male
  • hw -> fw -> sw
    • yus' projects
Re: Request PICMICRO codes here (C Only)
« Reply #32 on: April 24, 2009, 05:09:49 PM »
thanks, sir zer0! :)

una kong napansin:
pwede pala yung function na nagre-return na value ay lagyan lang ng (void) sa unahan.. :o

gusto ko sana yan i-apply sa memory card interfacing (SD card in SPI mode).
compatible ba yan sa physical layer ng memory card interfacing?
join  - Philippine Electronics and Robotics Enthusiasts Club - www.philrobotics.com

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Request PICMICRO codes here (C Only)
« Reply #33 on: April 24, 2009, 05:23:17 PM »
thanks, sir zer0! :)
gusto ko sana yan i-apply sa memory card interfacing (SD card in SPI mode).
compatible ba yan sa physical layer ng memory card interfacing?

You're welcome.
Pwede sa memory card.  Just take care of the large buffers needed to read and write.
The Cebuano Geek

Offline coolSkool

  • Size AAA Battery
  • ***
  • Posts: 62
  • Pogi/Ganda Points: 0
Re: Request PICMICRO codes here (C Only)
« Reply #34 on: April 29, 2009, 06:20:25 PM »
Kung sino po ang may alam kung paano yung codes para e display ang "Hello World" using LCD ng alexan interfacing to pic16f877. Using Hitech C or any equivalent C language.
Thank you.

Offline zer0w1ng

  • Technical People
  • Gas Turbine
  • *****
  • Posts: 2179
  • Pogi/Ganda Points: 305
  • Gender: Male
  • Enter any 11-digit prime number to continue...
    • The Cebuano Geek
Re: Request PICMICRO codes here (C Only)
« Reply #35 on: April 29, 2009, 06:43:06 PM »
Please search the forum. There are many LCD routines posted earlier here.
The Cebuano Geek

Offline paranz

  • Moderator
  • Nuclear Reactor
  • *****
  • Posts: 4525
  • Pogi/Ganda Points: 177
  • Gender: Male
  • 1/4W resistor specialist
    • RapidSignal Electronics
Re: Request PICMICRO codes here (C Only)
« Reply #36 on: June 02, 2009, 03:12:42 PM »
ang gusto ko po sanang matutunan using hi tech c ay ang pag gamit ng comparator ng PIC.

here is a sample code for comparator using PIC16F88. There are 8 possible comparator modes; this sample program uses mode 6 (Two common reference comparator with output). Refer to datasheet for more details on comparator operation.


main.c

Code: [Select]

#include <pic.h>
#include "pic16f_comparator.h"


__CONFIG(HS & MCLRDIS & WDTDIS & PWRTDIS & UNPROTECT & LVPDIS);

void main()
{
TRISA &= ~0x18;
init_comparator();

while(1)
{
//does nothing
}
}



pic16f_comparator.h

Code: [Select]

//macro
#define COMP_2IN_COM_REF_OUT 0x06

//function prototype
void init_comparator(void);




pic16f_comparator.c

Code: [Select]

#include <pic.h>
#include "pic16f_comparator.h"


void init_comparator(void)
{
C2INV = 0; //comparator 2 output not inverted
C1INV = 0; //comparator 1 output not inverted
CMCON &= ~0x07; //clear CM2:CM0 bits
CMCON |= COMP_2IN_COM_REF_OUT; //mode: Two common reference
//comparator with output

return;
}




to test the above code, connect 3 potentiometers to RA0, RA1, and RA2 and 2 LEDs to RA4 and RA3.

During program execution, if analog voltage at RA1 is lesser than analog voltage at RA2, RA4 will be logic 1 (LED1 on).

If analog voltage at RA0 is lesser than analog voltage at RA2, RA3 will be logic 1 (LED2 on).
PIC16 Programming Tutorial using MPLAB and Hi-Tech C
www.rapidsignalph.com/tutorials/pic16-tutorials

Arduino & gizDuino Tutorials
www.rapidsignalph.com/tutorials/arduino-tutorials

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Request PICMICRO codes here (C Only)
« Reply #37 on: June 05, 2009, 09:15:34 PM »
here is a sample code for comparator using PIC16F88. There are 8 possible comparator modes; this sample program uses mode 6 (Two common reference comparator with output). Refer to datasheet for more details on comparator operation.


main.c

Code: [Select]

#include <pic.h>
#include "pic16f_comparator.h"


__CONFIG(HS & MCLRDIS & WDTDIS & PWRTDIS & UNPROTECT & LVPDIS);

void main()
{
TRISA &= ~0x18;
init_comparator();

while(1)
{
//does nothing
}
}



pic16f_comparator.h

Code: [Select]

//macro
#define COMP_2IN_COM_REF_OUT 0x06

//function prototype
void init_comparator(void);




pic16f_comparator.c

Code: [Select]

#include <pic.h>
#include "pic16f_comparator.h"


void init_comparator(void)
{
C2INV = 0; //comparator 2 output not inverted
C1INV = 0; //comparator 1 output not inverted
CMCON &= ~0x07; //clear CM2:CM0 bits
CMCON |= COMP_2IN_COM_REF_OUT; //mode: Two common reference
//comparator with output

return;
}




to test the above code, connect 3 potentiometers to RA0, RA1, and RA2 and 2 LEDs to RA4 and RA3.

During program execution, if analog voltage at RA1 is lesser than analog voltage at RA2, RA4 will be logic 1 (LED1 on).

If analog voltage at RA0 is lesser than analog voltage at RA2, RA3 will be logic 1 (LED2 on).

palpak yung mga trials ko nito.hehe try ko tong code mo sir.hehe
if you think you can or think you can't, you're probably right -h.ford

Offline marcelino

  • Moderator
  • Solar Power Satellite
  • *****
  • Posts: 6016
  • Pogi/Ganda Points: 258
  • ...keep moving forward! - Robinson's
Re: Request PICMICRO codes here (C Only)
« Reply #38 on: June 08, 2009, 09:19:06 PM »
Dear folks, since many members are requesting for PIC codes, let this thread be our main repository for C codes written for any C compiler (hitech, ccs c, mikroc, sdcc, c18.. ).

Let me start


Here is a simple program. You can  simulate using Pr*teus  :)

Code: [Select]

//output a 10khz squarewave, 25% duty cycle signal at RC2/CCP1 pin
//PIC16F877 with 4 mhz clock


#include <pic.h>

__CONFIG(HS & WDTDIS & PWRTDIS & UNPROTECT);


void init_PWM(void)
{
//clear TMR2 relevant registers
CCP1CON = 0x00;
TMR2 = 0x00; //clear TMR2 register
TMR2ON = 0; //TMR2 is off

//configure TMR2 in PWM mode
CCP1CON = 0x0C; //PWM mode
T2CON &= ~0x03; //set prescaler, 1:1
PR2 = 0x60; //set period/frequency, ~10khz
CCPR1L = 0x18; //set duty cycle, ~40khz
CCP1CON &= ~0x30 ;

//PWM output pin
TRISC2 = 0;

//disable interrupts
PEIE = 0;
GIE = 0;

//enable TMR2
T2CON = 1; //PWM signal is generated.
//You can view the square wave signal
//using an oscilloscope, probe connected to
//RC2 pin
}

void main()
{
init_PWM();

while(1);
}





Can I ask for calculations for and explanations for this code?

//configure TMR2 in PWM mode
   CCP1CON = 0x0C;         //PWM mode -----------------> I get this. 0b00001100
   T2CON &= ~0x03;         //set prescaler, 1:1-------> ano nga an ibig sabihin nito?
   PR2 = 0x60;         //set period/frequency, ~10khz---------> papano naging approximately 10k?
   CCPR1L = 0x18;         //set duty cycle, ~40khz---------------> bakit ang duty cycle which is  in percentage, presented in Hz
   CCP1CON &= ~0x30 ; --------------------------------------------> once again, ano nga ang ibig sabihin nito?
"Don't take life seriously. After all, no one has ever come out of it alive. -Bugs Bunny"

Offline horde_fuego

  • Size C Battery
  • *****
  • Posts: 146
  • Pogi/Ganda Points: 2
  • Gender: Male
Re: Request PICMICRO codes here (C Only)
« Reply #39 on: June 08, 2009, 09:24:25 PM »
pwede rin po ba mag-request ng simple interrupt routine using timer 0 module ng PIC16F628A gamit na compiler ay CCS C?gusto ko na kasi matuto ng interrupts using timers kaso nakakatakot ang mga interrupts gamitin para saakin  >:( >:( >:(
kung pwede po simple application ay up counter hanggang 999.
salamat po ng marami!!!
if i lay here..if i just lay here..would you lie with me and forget the world...

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #39 on: June 08, 2009, 09:24:25 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com