Jump to content

huckster505

EstablishedMember
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

0 Neutral

About huckster505

  • Rank
    Newbrie
  1. Walshy, This is a fragment of program for a PIC16F873 which worked well. I hope you can get what you need from it. Huck //************************************************************* // * // Interface to Joystick * // * //************************************************************* // 7 Feb 2007 changed data conversion to prevent spillover top and bottom #include <system.h> #include "adc.inc" #pragma DATA 0x2007, _HS_OSC & _WDT_OFF & _LVP_OFF & _BODEN_OFF & _CPD_OFF & _PWRTE_ON #pragma CLOCK_FREQ 10000000 void output(short left, short right) { clear_bit(portc,6); // send output to "A" portb = left; clear_bit(portc,7); // delay_10us(1); // toggle "write" input set_bit(portc,7); // set_bit(portc,6); // send output to "B" portb = right; clear_bit(portc,7); // delay_10us(1); // toggle "write" input set_bit(portc,7); // } void main() { bit fault; char loop; short leftval,rightval,steerval,temp; signed short deflection,steer,left,right,diff; trisa = 0x3f; // all inputs trisb = 0x00; // all outputs trisc = 0x00; // all outputs adcon0 = 0x81; // initialize controller adcon1 = 0x82; // all analog; Vdd and Vss references set_bit(portc,6); set_bit(portc,7); fault = 0; //***************************************************************** // Begin interface functions * //***************************************************************** output (128,128); for (loop = 20; loop > 0; loop --){ clear_bit(portc,6); delay_ms(25); set_bit(portc,6); delay_ms(25); } while(1){ leftval = adc_measure(0); // acquire inputs delay_10us(2); rightval = adc_measure(1); delay_10us(2); clear_bit(portc,6); steerval = adc_measure(2); if((leftval > 800)|(leftval < 200)){ output(128,128); while(1){} }
  2. Dear Myrmidon, Notice that after your time delay you set the port B conditions and the program returns to the top...where they are immediately reset to initial condition. If you add another 1 second delay at end of while block, the LED block will behave as you desire (I think) Good Luck and Enjoy Huck
  3. huckster505

    Adc

    sri about that.. Using Sourceboost Ver. 6.3, boostC also ref. edited first post. tnx again.
  4. huckster505

    Adc

    I believe that adc.h or adc.inc needs to be modified to resolve use of adc_on or adc_go bitname. adc.inc uses adc_on and causes error on build. Modified adc.inc adc_on=1; to set_bit(adcon0,ADON); all is again happy
  5. Dave, Using 6.11 Regards, Huck
  6. Gentlemen; The program fragment below illustrates what I believe to be a bug. It is intended to drive an LED bargraph, but always produces a dark display. When I replaced the variable governing the shift in the portb assignment, the display works properly; and the .casm results show this. However, the portc assignment results in assembly which will shift the temporary variable Con_Temp_Var85 the proper number of times with the count variable "fuel" tracked in "W". When "W" reaches 0, the value in "W" (now 0) is moved to portc. C program fragment: disp = 0x01; // turn on bit portb = disp << 3; // shift to desired location disp = 0x01; // turn on bit portc = disp << fuel; // shift to desired location .casm file fragment: disp = 0x01 // turn on bit 01AC 3001 MOVLW 0x01 01AD 00A6 MOVWF main_1_disp portb = disp << 3; // shift to desired location 01AE 00B0 MOVWF CompTempVar84 01AF 0DB0 RLF CompTempVar84, F 01B0 0DB0 RLF CompTempVar84, F 01B1 0D30 RLF CompTempVar84, W 01B2 39F8 ANDLW 0xF8 01B3 0086 MOVWF gbl_portb disp = 0x01 // turn on bit 01B4 3001 MOVLW 0x01 01B5 00A6 MOVWF main_1_disp portc = disp << fuel; // shift to desired location 01B6 00B0 MOVWF CompTempVar85 01B7 0824 MOVF main_1_fuel, W 01B8 label268436719 01B8 39FF ANDLW 0xFF 01B9 1903 BTFSC STATUS,Z 01BA 29BF GOTO label268436720 01BB 1003 BCF STATUS,C 01BC 0DB0 RLF CompTempVar85, F 01BD 3EFF ADDLW 0xFF 01BE 29B8 GOTO label268436719 01BF label268436720 01BF 0087 MOVWF gbl_portc On edit: using BoostC... sri Thanks, Huck
×
×
  • Create New...