Jump to content

Akropolis

EstablishedMember
  • Content Count

    5
  • Joined

  • Last visited

Posts posted by Akropolis


  1. Hi,

     

    I'm trying to hook up my 16F628 to my computer via RS232. I connected the TX to the RX of the pc, the RX to the TX and pin 5 the ground.

    The PIC is sending something, but my pc isn't receiving it properly I think.

     

    This is what I receive:

     

    1.JPG

     

    Port settings:

     

    2.JPG

     

    And my code:

     

    #include <system.h>
    
    #pragma CLOCK_FREQ 20000000
    
    #include <system.h>
    
    #define TX_PORT		 0x06
    #define TX_TRIS		 0x86
    #define TX_BIT		  2
    #define RX_PORT		 0x06
    #define RX_TRIS		 0x86
    #define RX_BIT		  1
    #define e_SPBRG		 0x99
    #define e_RCREG		 0x1a
    #define e_TXREG		 0x19
    #define e_TXSTA		 0x98
    #define e_RCSTA		 0x18
    #define e_TXIF_PIR	  0x0c
    #define e_RCIF_PIR	  0x0c
    #define e_TXIF_BIT	  4
    #define e_RCIF_BIT	  5
    #define MODE			(USART_reset_wdt | USART_HW)
    
    
    #pragma DATA _CONFIG, _HS_OSC & _WDT_OFF & _LVP_OFF & _MCLRE_OFF
    
    
    #define spBAUD  9600
    #define FOSC 20000000L
    #define fSPBCLK (FOSC)		/* UART Baud rate generator clock (high speed) */
    //#define fSPBCLK (FOSC / 4)	/* UART Baud rate generator clock (low speed) */
    #define SPBRG_VAL (fSPBCLK / (spBAUD * 16L)) - 1L
    
    #define bit_time 129 
    
    #include <rs232_driver.h>
    
    void main()
    {	
    // serial config
    txsta = 00110000b;
    rcsta = 10000000b;
    
    // input serial
    set_bit(trisb, 1);
    
    // output serial
    clear_bit(trisb, 2);
    
    uart_init(1,SPBRG_VAL);  
    
    while(true)
    {
    	puts("test");
    	delay_ms(500);
    }
    }

     

    Is my USART setup wrong or do I need some extra hardware to connect my PIC to my PC?

     

    Thanks in advance!


  2. I'm trying to send something using the the rs232_driver.h. I tried quite a few things, but I always get the same error.

     

    #pragma CLOCK_FREQ 4000000
    
    #include <system.h>
    #include <rs232_driver.h>
    
    #define bit_time 104 // For RS232 - (not used but required for compiling)
    
    #pragma DATA 0x2007, _HS_OSC & _WDT_OFF & _LVP_OFF
    
    void main()
    {	
    uart_init(1,25);  // set high speed divisor mode and divisor value
    }

     

    This is the minimum amount of code I need to get the error. ;)

     

    Error:

    Building...
    BoostC Optimizing C Compiler Version 6.55 (for PIC16 architecture)
    http://www.sourceboost.com
    Copyright(C) 2004-2006 Pavel Baranov
    Copyright(C) 2004-2006 David Hobday
    
    Single user Lite License (Unregistered) for 0 node(s)
    Limitations: PIC12,PIC16 max code size:2048 words, max RAM banks:2, Non commercial use only
    
    
    rs232.c
    
    failure
    C:\Program Files\SourceBoost\include\rs232_driver.h(457:27): error: failed to generate expression
    C:\Program Files\SourceBoost\include\rs232_driver.h(457:27): error: invalid operand 'GETC<TX_BIT, TX_PORT, TX_TRIS, RX_BIT, RX_PORT, RX_TRIS, e_SPBRG, e_RCREG, e_TXREG, e_TXSTA, e_RCSTA, e_TXIF_BIT,e_TXIF_PIR, e_RCIF_BIT, e_RCIF_PIR, MODE>()'
    C:\Program Files\SourceBoost\include\rs232_driver.h(457:25): error: failed to generate expression
    C:\Program Files\SourceBoost\include\rs232_driver.h(457:25): error: invalid operand '= '
    C:\Program Files\SourceBoost\include\rs232_driver.h(457:185): error: failed to generate expression
    C:\Program Files\SourceBoost\include\rs232_driver.h(457:185): internal error: failed to generate 'while' expression
    C:\Program Files\SourceBoost\include\rs232_driver.h(457:2): error: error in 'while' loop statement
    C:\Program Files\SourceBoost\include\rs232_driver.h(465:2): error: failed to generate expression
    C:\Program Files\SourceBoost\include\rs232_driver.h(465:2): error: Error in the body of 'while' expression
    C:\Program Files\SourceBoost\include\rs232_driver.h(466:2): error: failed to generate expression
    C:\Program Files\SourceBoost\include\rs232_driver.h(467:2): error: failed to generate expression
    P:\PIC\MoniLED Mainunit.c(31:2): error: failed to generate expression
    "C:\Program Files\SourceBoost\boostc.pic16.exe" "rs232.c" -t PIC16F876 
    Exit code was 1.
    Removing target: rs232.obj
    Done

     

    I am using a PIC16F876 @ 4 Mhz. Any idea why this error?

     

    Thanks in advance


  3. Hi, some time ago I started experimenting with PICs. Untill now I could find everything I didn't know here. My problem is that as soon as I call the beep() function porta.0 gets set to 0? I have no idea how this is possible, anyone got any ideas?

     

    Sounds like the 'read, modify, write' problem

     

    For further details search the relevant data sheet, microchips website or google for read, modify, write

     

    Thanks for the reply's B) . And I found the problem. It was the 'read, modify, write' problem.

     

    New code:

     

    /* test program */
    #include <system.h>
    
    // standaard voor de 16F serie
    #pragma DATA 0x2007, _HS_OSC & _WDT_OFF & _LVP_OFF
    
    #pragma CLOCK_FREQ 4000000
    
    // beepie
    void beep(int dur, int tmp_porta)
    {
    int i;
    
    for (i = 0; i < dur; i++)
    {	
    	tmp_porta.5 = 1;
    	porta = tmp_porta;
    	delay_100us(2);// delay
    	tmp_porta.5 = 0;
    	porta = tmp_porta;
    	delay_100us(2);// delay
    }
    }
    
    void main()
    {
    int tmp_porta = 0;
    
    trisa = 00000000b;
    trisc = 00000000b;
    
    trisb = 00001111b;
    
    
    // zet alle poorten op digitaal
    adcon1 = 0x0F; // eerste 4 bits op 1 zette (digitaal dus)
    
    // one led on both ports
    tmp_porta.0 = 1;
    porta = tmp_porta;
    portc.3 = 1;
    
    while (1)
    {
    	// if button is pressed
    	if (portb.0 == 1)
    	{
    		beep(1000, tmp_porta);
    	}
    }
    }


  4. Hi, some time ago I started experimenting with PICs. Untill now I could find everything I didn't know here. My problem is that as soon as I call the beep() function porta.0 gets set to 0? I have no idea how this is possible, anyone got any ideas?

     

    Thanks in advance B)

     

    My partial program code:

     

    /* test program */
    #include <system.h>
    
    // standaard voor de 16F serie
    #pragma DATA 0x2007, _HS_OSC & _WDT_OFF & _LVP_OFF
    
    #pragma CLOCK_FREQ 4000000
    
    // beepie
    void beep(int dur)
    {
    int i;
    
    for (i = 0; i < dur; i++)
    {	
    	porta.5 = 1;
    	delay_100us(2);// delay
    	porta.5 = 0;
    	delay_100us(2);// delay
    }
    }
    
    void main()
    {
    
    trisa = 00000000b;
    trisc = 00000000b;
    
    trisb = 00001111b;
    
    // one led on both ports
    porta.0 = 1;
    portc.3 = 1;
    
    while (1)
    {
    	// if button is pressed
    	if (portb.0 == 1)
    	{
    		beep(1000);
    	}
    }
    }

×
×
  • Create New...