caramoan tour package

caramoan tour package

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

Offline Soulchii

  • CR2032 Battery
  • **
  • Posts: 20
  • Pogi/Ganda Points: 0
Re: Request PICMICRO codes here (C Only)
« Reply #260 on: March 01, 2011, 05:42:35 AM »
Pa edit naman po ako ng C code ko para sa sumobot ko kasi yung pins r0-r3 ndi nya narearead as input .. output sya kc nakakabit yung proximity ko dun tapos yung indicator na led naka on kahit walang object tapos di nya din finefetch yung input ng sensor port b lang po gamit ko yung prox ko nasa rb2 po tapos ung rb1 at rb3 ay line sensor .. pag naka onn po xa forward lang sya pahelp po thanks!
Code: [Select]
#include <pic.h>
//configuration fuses
__CONFIG(XT & WDTDIS & PWRTDIS & UNPROTECT);
void delay(void) //this is a delay function
{
unsigned int i;
for(i=0;i<0xFFFF;i++) //FOR loop does nothing, just
; //increment variable i from 0
} //to 65535
void main ()
{
TRISB = 0b00001111; //RB7-4 are output pins
if (TRISB2 = 0)
{
PORTB = 0b10100000; //forward
}
else
{
PORTB = 0b00010000; //turn left
}
if (TRISB3 = 0)
{
PORTB = 0b10100000; //forward
}
else
{
PORTB = 0b01000000; //turn right
}
if (TRISB1 = 0 )
{
PORTB = 0b10010000; //search
}
else
{
PORTB = 0b10100000; //forward
}
while(1) //infinite loop
{
delay(); //invoke delay() function
}
}

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #260 on: March 01, 2011, 05:42:35 AM »

Offline sniper73

  • LR44 Battery
  • *
  • Posts: 1
  • Pogi/Ganda Points: 0
Re: Request PICMICRO codes here (C Only)
« Reply #261 on: July 18, 2011, 12:56:44 PM »
heto ang gamit ko, macro tsaka bit operators and shifts


pwm.h

Code: [Select]

//********************* MODIFY HERE *****************************
#ifndef FOSC_FREQ
#define FOSC_FREQ 20MHZ /* Crystal frequency in MHz */
#endif

#define MHZ *1000000L //dont modify
#define KHZ *1000L         //dont modify

#define PWM_MODE 0x0C //00001100
#define PWM_FREQ 100KHZ //khz
#define TMR2_PRES 1 //prescaler = 1,4,16
#define DUTY_CYCLE 50 //duty cycle in %
//****************************************************************

#define PR2_VALUE ((FOSC_FREQ / (PWM_FREQ * 4 * TMR2_PRES)) - 1)
#define PWM_DC_FREQ ((PWM_FREQ * 100) / DUTY_CYCLE)
#define _10BIT_DUTY_CYCLE         (FOSC_FREQ / (PWM_DC_FREQ * TMR2_PRES))


void init_PWM(void);



pwm.c
Code: [Select]

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

//assign prescaler
switch(TMR2_PRES){
case 1:
T2CON &= ~0x03;
break;
case 4:
T2CON |= 0x01;
break;
case 16:
T2CON |= 0x02;
break;

}

//configure TMR2 in PWM mode
CCP1CON |= PWM_MODE; //PWM mode
PR2 = PR2_VALUE; //set PWM frequency

//assign duty cycle
CCPR1L = (_10BIT_DUTY_CYCLE >> 2);
CCP1CON |= (_10BIT_DUTY_CYCLE << 4) & 0x30;


//PWM output pin
TRISC2 = 0;

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

//enable PWM
TMR2ON = 1;
}



tanong ko lang po, pano gamitin yong pwm.h at pwm.c?
kasi po may gagawin kami na project may part na kelangan icontrol ung RPM ng motor..
diba ichange lang ang duty cycle nyan? pano ko po gagamitin ung pwm.h at .c para magawa yon? TIA

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #261 on: July 18, 2011, 12:56:44 PM »

Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: Request PICMICRO codes here (C Only)
« Reply #262 on: October 16, 2011, 12:33:24 AM »
Upppp.... ;D
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #262 on: October 16, 2011, 12:33:24 AM »

Offline dummy_c

  • Diesel Generator
  • *
  • Posts: 1588
  • Pogi/Ganda Points: 162
  • Gender: Male
  • If I die 2nyt, 8's bcoz maimai is not at my side!
Re: Request PICMICRO codes here (C Only)
« Reply #263 on: October 16, 2011, 08:28:16 AM »
mga master, hindi ko tlga makuha sa PIC to PIC Tx to Rx, transfer po sana ako ng 1word character.. baka meron po kayo smple program in mikroC po baka pwd po makahingi, kahit ung pinaka simple lang po, basta matransmit niya ung word then e display ng receiver PIC sa LCD, nahihirapan po ako mag program ng uart, paki check na lang po if may mali sa mga connections ko po.. tnx po tlg, ..

eto po ung image






TX

Quote
   unsigned char _data = 0x41;
   unsigned char _data1 = 0x42;
   unsigned char _data2 = 0x43;
   unsigned char _data3 = 0x44;
void main(){
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  delay_ms (2000);
 
  do {
  UART1_Write(_data);
  delay_ms(1000);
  UART1_Write(_data1);
  delay_ms(1000);
  UART1_Write(_data2);
  delay_ms(1000);
  UART1_Write(_data3);
  delay_ms(1000);
  } while (1);
}


RX
Code: [Select]
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections


unsigned char uart_rd;
unsigned char temp;
void main(){

  Lcd_Init();                        // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR);               // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);          // Cursor off
  UART1_Init(9600);               // Initialize UART module at 9600 bps
  delay_ms (1000);
  do {
    if (UART1_Data_Ready() == 1) {
      uart_rd = UART1_Read();
      UART1_Write(uart_rd);
      temp = uart_rd;
      }
    Delay_ms(100);
    Lcd_Chr(1,2, temp);
 
  } while (1);


}




I know matagal na ito, pinag practisan lang.. ;D
Very basic po ito using mikroC.
The world's technology is always changing, no doubt about it, and I hope it’s a while yet before it impacts my ability to tinker.

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #263 on: October 16, 2011, 08:28:16 AM »

Offline fran2no

  • Size AA Battery
  • ****
  • Posts: 129
  • Pogi/Ganda Points: 5
  • Gender: Male
Re: Request PICMICRO codes here (C Only)
« Reply #264 on: October 16, 2011, 04:27:00 PM »
up

Philippine Electronics Forum

Re: Request PICMICRO codes here (C Only)
« Reply #264 on: October 16, 2011, 04:27:00 PM »

 

Privacy Policy

Contact Us: elabph@yahoo.com