Jump to content

MrNobody

EstablishedMember
  • Content count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral

About MrNobody

  • Rank
    Newbrie
  1. Oh... thank u thank u thank u thank u.......
  2. Hi.. I need some advice on how to set port A of PIC16F877A as input correctly.. Below is a code that when input RA0 is HIGH, LED on RD0 will turn on (at least that is what I plan for it to do). When RA1 is high, LED on RD1 will turn on etc.. The input I have is from RA0 to RA4.. But the code doesn't seem to work.. It doesn't recognise the input at port A.. I have already set the trisa to input but still no result.. Can somebody please advise.. thanks.. #include <system.h> //Target PIC16F877 configuration word #pragma DATA _CONFIG, _PWRTE_OFF & _BODEN_OFF & _WDT_OFF & _LVP_ON & _CPD_OFF & _DEBUG_OFF & _HS_OSC & _CP_OFF //Set clock frequency #pragma CLOCK_FREQ 4000000 // Variable declaration int Code; // the Code that is received (eg 10000 is mode) int Direction = 0; int AutoMode = 0; int AutoCount = 0; int Loop = 0; void main( void ) { //Configure port A trisa = 0xFF; //Configure port B trisb = 0x00; //Configure port C trisc = 0xFF; //Configure port D trisd = 0x00; //Configure port E trise = 0x00; //Initialize port A porta = 0x00; //Initialize port B portb = 0x00; //Initialize port C portc = 0x00; //Initialize port D portd = 0x00; //Initialize port E porte = 0x00; //Endless loop while( 1 ) { Main: Code = porta; if (Code == 0b00001) goto Normal_1; else if (Code == 0b00010) goto Speed_1; else if (Code == 0b00100) goto Automatic_1; else if (Code == 0b01000) goto Sensor_1; else if (Code == 0b01000) goto Mode_1; } Normal_1: portd = 0x00; set_bit(portd, 0); goto Main; Speed_1: portd = 0x00; set_bit(portd, 1); goto Main; Automatic_1: portd = 0x00; set_bit(portd, 2); goto Main; Sensor_1: portd = 0x00; set_bit(portd, 3); goto Main; Mode_1: portd = 0x00; set_bit(portd, 4); goto Main; }
  3. Hi.. Can somebody please teach me how to convert the code below into BoostC..? I have some basic knowledge on BoostC but I totally have no knowledge of HITECH PIC16 compiler.. So, I don't even know how to begin.. Thanks in advance.. Here is the code //////////////////////////////////////////////////////////////////////////////// // // PIC16F877 + SRF05 + LCD03 example // Written October 2005 by Gerald Coe, using HITECH PIC16 compiler // // Performs ranging using just a single pin on the PIC16F877 (RB0) // // Note - assumes a 20MHz crystal, which is 5MHz timer clock // A 1:4 prescaler is used to give a 1.25MHz timer count (0.8uS per tick) // // This code is Freeware - Use it for any purpose you like. // /////////////////////////////////////////////////////////////////////////////// #include <pic.h> #include <stdio.h> __CONFIG(0x3b32); // configuration register - see PIC data sheet for details #define TrgEch RB0 #define TrgDir TRISB0 void clrscn(void); // prototypes void cursor(char pos); void print(char *p); void setup(void); unsigned int get_srf05(void); char s[21]; // buffer used to hold text to print void main(void) { unsigned int range; setup(); // sets up the PIC16F877 I2C port clrscn(); // clears the LCD03 disply cursor(2); // sets cursor to 1st row of LCD03 sprintf(s,"SRF05 Ranger Test"); // text, printed into our buffer print(s); // send it to the LCD03 while(1) { // loop forever range = get_srf05(); // get range from srf05 (round trip flight time in 0.8uS units) cursor(24); // sets cursor to 2nd row of LCD03 sprintf(s,"Range = %dcm ", range/72); // convert to cm print(s); // send it to the LCD03 cursor(44); // sets cursor to 3rd row of LCD03 sprintf(s,"Range = %dinch ", range/185); // convert to inches print(s); // send it to the LCD03 TMR1H = 0; // 52mS delay - this is so that the srf05 ranging is not too rapid TMR1L = 0; // and the previous pulse has faded away before we start the next one T1CON = 0x21; // 1:4 prescale and running TMR1IF = 0; while(!TMR1IF); // wait for delay time TMR1ON = 0; // stop timer } } unsigned int get_srf05(void) { TMR1H = 0xff; // prepare timer for 10uS pulse TMR1L = -14; T1CON = 0x21; // 1:4 prescale and running TMR1IF = 0; TrgDir = 0; // make trigger/echo pin an output TrgEch = 1; // start trigger pulse while(!TMR1IF); // wait 10uS TrgEch = 0; // end trigger pulse TMR1ON = 0; // stop timer TrgDir = 1; // make trigger/echo pin an input TMR1H = 0; // prepare timer to measure echo pulse TMR1L = 0; T1CON = 0x20; // 1:4 prescale but not running yet TMR1IF = 0; while(!TrgEch && !TMR1IF); // wait for echo pulse to start (go high) TMR1ON = 1; // start timer to measure pulse while(TrgEch && !TMR1IF); // wait for echo pulse to stop (go low) TMR1ON = 0; // stop timer TrgDir = 0; // make trigger/echo pin an output again return (TMR1H<<8)+TMR1L; // TMR1H:TMR1L contains flight time of the pulse in 0.8uS units } void clrscn(void) { SEN = 1; // send start bit while(SEN); // and wait for it to clear SSPIF = 0; SSPBUF = 0xc6; // LCD02 I2C address while(!SSPIF); // wait for interrupt SSPIF = 0; // then clear it. SSPBUF = 0; // address of register to write to while(!SSPIF); // SSPIF = 0; // SSPBUF = 12; // clear screen while(!SSPIF); // SSPIF = 0; // SSPBUF = 4; // cursor off while(!SSPIF); // SSPIF = 0; // PEN = 1; // send stop bit while(PEN); // } void cursor(char pos) { SEN = 1; // send start bit while(SEN); // and wait for it to clear SSPIF = 0; SSPBUF = 0xc6; // LCD02 I2C address while(!SSPIF); // wait for interrupt SSPIF = 0; // then clear it. SSPBUF = 0; // address of register to write to while(!SSPIF); // SSPIF = 0; // SSPBUF = 2; // set cursor while(!SSPIF); // SSPIF = 0; // SSPBUF = pos; // while(!SSPIF); // SSPIF = 0; // PEN = 1; // send stop bit while(PEN); // } void print(char *p) { SEN = 1; // send start bit while(SEN); // and wait for it to clear SSPIF = 0; SSPBUF = 0xc6; // LCD02 I2C address while(!SSPIF); // wait for interrupt SSPIF = 0; // then clear it. SSPBUF = 0; // address of register to write to while(!SSPIF); // SSPIF = 0; // while(*p) { SSPBUF = *p++; // write the data while(!SSPIF); // SSPIF = 0; // } PEN = 1; // send stop bit while(PEN); // } void setup(void) { unsigned long x; PORTB = 0xfe; // RB0 (trig) is output TRISB = 0xfe; // and starts low TRISC = 0xff; PORTC = 0xff; SSPSTAT = 0x80; SSPCON = 0x38; SSPCON2 = 0x00; SSPADD = 50; // SCL = 91khz with 20Mhz Osc for(x=0; x<300000L; x++); // wait for LCD03 to initialise }
  4. Really sorry for the wrong title mods and people.. Initially, when I typed this post, I thought that the programming was written in ASM.. but then I realised that the code was actually written in Pic Basic (I think).. I am new to the world of PIC programming.... -Original Message- Hi, Below is a code to calculate the number of pulses and convert it into RPM to display in LCD.. If I am not mistaken, it is written in Pic Basic rite..? Can somebody please teach me how to convert it to C language (BoostC)..? Thanks.. Device = 16F877 Xtal = 20 Dim Result as DWord LCD_DTPIN = PORTB.4 ' Setup the LCD LCD_RSPIN = PORTB.2 ' LCD_ENPIN = PORTB.3 ' LCD_INTERFACE = 4 ' LCD_LINES = 2 ' LCD_TYPE = 0 ' All_Digital = True ' Make all pins Digital I/O's While 1 = 1 Result = COUNTER PORTA.0, 100 ' Count how many pulses in 100mS Result = Result * 10 * 60 ' Scale To RPM Print at 1, 1, "RPM = ", DEC8 Result ' Display on the LCD Wend ' Loop for ever
  5. Hi.. I use BoostC to write a Traffic Light code. After writing it, I download the code onto PIC16F84A and it work fine there.. But when I use the hex code generated on Proteus ISIS' traffic light, it doesn't work there.. The RB3 and RB4 pin on for unlimited amount of time. Due to the working environment I am in, actual hardware simulation is not practical. So, I need to use Proteus to simulate more complicated circuits... Do anybody know how I can make hex code generated by BoostC run in Proteus..? Help would be very much appreciated. Thanks in advance..
  6. Hi.. I use BoostC to write a Traffic Light code. After writing it, I download the code onto PIC16F84A and it work fine there.. But when I use the hex code generated on Proteus ISIS' traffic light, it doesn't work there.. The RB3 and RB4 pin on for unlimited amount of time. Due to the working environment I am in, actual hardware simulation is not practical. So, I need to use Proteus to simulate more complicated circuits... Do anybody know how I can make hex code generated by BoostC run in Proteus..? Help would be very much appreciated. Thanks in advance..
×